Recently, due to the customer's new requirements, we need to import data into PDF format. I have read a lot on the Internet. Although it is not comprehensive, I still want to thank them, I have sorted out all the code they have written and posted it for your reference. Www.2cto.com
Using iTextSharp. text;
Using iTextSharp.text.pdf;
// Remember that the above two DLL namespaces must be referenced.
Document document = new Document ();
Using writer. GetInstance (document, new FileStream ("c: // 123.pdf", FileMode. Create ));
Document. Open ();
BaseFont bfChinese = BaseFont. CreateFont ("C: // WINDOWS // Fonts // simsun. ttc, 1", BaseFont. IDENTITY_H, BaseFont. NOT_EMBEDDED );
ITextSharp. text. font fontChinese = new iTextSharp. text. font (bfChinese, 12, iTextSharp. text. font. NORMAL, new iTextSharp. text. color (0, 0, 0 ));
// Export the text content:
Document. Add (new Paragraph ("hello", fontChinese ));
// Export the image:
ITextSharp. text. Image jpeg = iTextSharp. text. Image. GetInstance (Path. GetFullPath ("1.jpg "));
Document. Add (jpeg );
// Be sure to disable it. Otherwise, the content in the PDF will not be saved.
Document. Close ();
Author: Sky_Cat