C # editor
Mostrar más instrucciones
1
 Abra un editor de C # . 
 2 
 Crear un archivo de C # y añadir . el siguiente código 
 3 
 Utilice un espacio de nombres para llamar a la biblioteca iTextSharp : 
 
 usando iTextSharp.text ; 
 
 usando iTextSharp.text.pdf ; 
 4 
 Llame una clase incorporada en iTextSharp y establecer el StringBuilder al vacío : 
 
 documento documento = new documento ( PageSize.A4 , 80 , 50, 30 , 65) ; 
 
 StringBuilder strData = new StringBuilder ( String.Empty ) ; 
 5 
 Añade una ruta de acceso para el código HTML que se generen a partir del contenido GridView : 
 
 cadena strHTMLpath = Server. MapPath ( " MyHTML.html "); 
 6 
 defina la ruta para el archivo PDF para construir : 
 
 cadena strPDFpath = Server.MapPath ( " MyPDF.pdf "); 
 7 
 Llama a los datos desde el archivo HTML y hacer el archivo: 
 
 StringWriter sw = new htw = new HtmlTextWriter ( sw) ; 
 
 gvSerchResult.AllowPaging = false; 
 
 gvSerchResult.AllowSorting = false; 
 
 BindGridView (); 
 
 gvSerchResult . RenderControl ( HTW ) ; 
 
 StreamWriter strWriter = new StreamWriter ( strHTMLpath , falso , Encoding.UTF8 ) ; 
 
strWriter.Write ( " html head < /head>
" htw.InnerWriter.ToString + () + " < /body> < /html > ") ; strWriter.Close (); 
 
 strWriter.Dispose ( ) ; 
 8 
 Utilice el analizador de convertir el contenido HTML a PDF : 
 
 iTextSharp.text.html.simpleparser 
 
 estilos StyleSheet = new iTextSharp . . text.html.simpleparser.StyleSheet (); 
 
 styles.LoadTagStyle ( " mujeres de negocios" , "llevar ", " 16,0 "); 
 
 PdfWriter.GetInstance (documento , nuevo FileStream ( strPDFpath , FileMode.Create )); 
 
 document.open (); 
 9 
 Establecer los estilos de fuente para los elementos de la página y añadir los elementos de la página : 
 < p > objetos ArrayList ; 
 
 styles.LoadTagStyle ( "li" , "cara ", " Garamond "); 
 
 styles.LoadTagStyle ( "span" , "tamaño" , " 8px "); 
 
 styles.LoadTagStyle ( "cuerpo", " font-family ", " times new roman" ) ; 
 
 styles.LoadTagStyle ( "cuerpo", "font -size" , " 12px " ) ; 
 
 document.NewPage ( ) . 
 objetos 
 = iTextSharp.text.html.simpleparser 
 
 HTMLWorker.ParseToList ( new StreamReader ( strHTMLpath , Encoding.Default ) , estilos) ; 
 
 for (int k = 0 , k < objects.Count ; k + +) { 
 
 
 
 document.Add ( ( IElement ) objetos [ k ] ) ; 
 
 } 
 10 
 Borrar todas las variables utilizadas en la memoria y cierre : 
 
 { 
 
 document.close (); 
 
 Response.Write ( Server.MapPath ( "~ /" + "attachment ; filename = " + strPDFpath ) ; 
 
 Response.ContentType = "application /octet -stream" ; 
 
 Response.WriteFile ( Server.MapPath ( "~ /" + strPDFpath ) ) ; 
 
 Response.Flush (); 
 
 Response.Close (); 
 
 if ( File.Exists ( Server.MapPath ( "~ /" + strPDFpath ))) 
 
 { 
 
 File.Delete ( Server.MapPath ( "~ /" + strPDFpath )); } 
 
 
 
 } 
 11 
 Ejecute el archivo de C # para crear el archivo PDF desde el archivo HTML. 
 
 
          
