Java export pdf document
Java exports pdf documents, mostly implemented by iText. You can create pdf documents and write content to them.
1 import package: A required package for the itext-2.0.6.jar itext.
ITextAsian. jar writes a required Chinese package to pdf.
2 code:
Package com.exp;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=. baseFont; import com.lowagie.text.pdf. extends writer; public class PDFUtil {public static void main (String [] args) {createPdf ();} public stati C void createPdf () {try {// create a test Document document Document = new document (PageSize. a4, 50,50, 50,50); valid writer = valid writer. getInstance (document, new FileOutputStream (c: \ test.pdf); // you must specify the font when writing data to the Chinese language. Otherwise, the data cannot be written to the Chinese language and iTextAsian is required. jarBaseFont bf = BaseFont. createFont (STSong-Light, UniGB-UCS2-H, BaseFont. NOT_EMBEDDED); Font font = new Font (bf, 12, Font. NORMAL); document. open (); document. add (new Paragraph (Chinese test !, Font); document. add (new Paragraph (some more); // specify the font format document. add (new Paragraph (some more, FontFactory. getFont (FontFactory. COURIER, 14, Font. BOLD, new Color (255,150,200); document. close ();} catch (Exception e) {e. printStackTrace ();}}}