Exporting PDFs with the Itext component

Source: Internet
Author: User

Maven dependencies:

<dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> < version>5.2.0</version> </dependency><!--PDF Output Chinese extension pack--<dependency> <groupid& Gt;com.itextpdf</groupid> <artifactId>itext-asian</artifactId> <version>5.2.0</ Version></dependency>


Operation:

package excel;import java.io.fileoutputstream;import java.io.fileoutputstream;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;/** *  Export PDF with Itext   Documentation  *  *  @author  gie * */public class creatpdf {public  static void main (String[] args)  {document doc = null;try {doc  = new document (); Pdfwriter.getinstance (Doc, new fileoutputstream ("C:\\itext.pdf"));d Oc.open ();d oc.addtitle ("test title"); Doc.addauthor ("Gie");d oc.addcreationdate ();d oc.addsubject ("test subject");// itext  Chinese processing basefont  Bfchinese = basefont.createfont ("Stsong-light",  "Unigb-ucs2-h",  basefont.not_embedded); Font fontchinese = new font (Bfchinese, 12, font.normal); paragraph pragraph&Nbsp;= new paragraph ("Hello",  fontchinese);d Oc.add (pragraph);}  catch  (exception e)  {e.printstacktrace ();}  finally {doc.close ();}}}

Key points:

IText itself does not support Chinese needs expansion pack

Exporting PDFs with the Itext component

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.