Itext Exporting PDFs

Source: Internet
Author: User

Related ja bag: Itext-5.0.6.jar,itextasian-1.5.2.jar.

Note: You must modify the package path in the Itextasian-1.5.2.jar with WinRAR or haozip to change the package path to com.itextpdf.text.pdf.fonts. Otherwise, the PDF-times error is generated.

Example code:

Package com.xy6;
Import Java.io.File;
Import Java.io.FileOutputStream;
Import Java.io.OutputStream;

Import Java.util.Date;
Import Com.itextpdf.text.BaseColor;
Import com.itextpdf.text.Document;
Import Com.itextpdf.text.Font;
Import Com.itextpdf.text.Paragraph;
Import Com.itextpdf.text.pdf.BaseFont;

Import Com.itextpdf.text.pdf.PdfWriter; public class Demo1 {/** * @param args */public static void main (string[] args) {try{outputstream file = NE
			W FileOutputStream (New File ("E:/demo1.pdf"));
			Document doc = new document ();
			Pdfwriter.getinstance (doc, file);
			Doc.open ();
			Basefont Bfchinese = Basefont.createfont ("Stsongstd-light", "Unigb-ucs2-h", false);

			Font Fontchinese = new Font (bfchinese,12,font.normal,basecolor.black);
			Paragraph PF = new Paragraph ("abc");
			Pf.add (New Paragraph ("Shenzhen", Fontchinese));
			Pf.add (New Paragraph () (New Date (). toString ()));

			Doc.add (PF);
			Doc.close ();
			File.close ();
		SYSTEM.OUT.PRINTLN ("---done");
	} catch (Exception ex) {		Ex.printstacktrace (); }
	}

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.