Java Export PDF document

Source: Internet
Author: User

Java exports PDF documents, mostly Itext, to create PDF documents and write content to documents.

1 Import Package: Itext-2.0.6.jar Itext must use the package.

Itextasian.jar write the required package to PDF in Chinese.


2 Code:

Package Com.exp.pdf;import Java.awt.color;import Java.io.fileoutputstream;import com.lowagie.text.document;import Com.lowagie.text.font;import Com.lowagie.text.fontfactory;import Com.lowagie.text.pagesize;import Com.lowagie.text.paragraph;import Com.lowagie.text.pdf.basefont;import Com.lowagie.text.pdf.pdfwriter;public Class Pdfutil {public static void main (string[] args) {createpdf ();} public static void CreatePDF () {try {//Create a test document in the C-disk document=new documents (pagesize.a4,50,50,50,50); PDFWriter writer=pdfwriter.getinstance (document, New FileOutputStream ("C:\\test.pdf"))//The font must be specified when writing to Chinese, otherwise it cannot be written in Chinese , Need Itextasian.jarbasefont Bf=basefont.createfont ("Stsong-light", "unigb-ucs2-h", basefont.not_embedded); Font font=new font (bf,12,font.normal);d ocument.open ();d Ocument.add (New Paragraph ("Chinese test! ", font));d Ocument.add (New Paragraph (" some more "));//Specify Font format document.add (new Paragraph (" Some more ", Fontfactory.getfont (fontfactory.courier,14,font.bold,new Color (255,150,200))));d ocument.close (); catch (EXception e) {e.printstacktrace ();}}} 

Java Export PDF document

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.