Java output PDF

Source: Internet
Author: User

Package Snake;import;import;import;import;import;import Com.lowagie.text.document;import Com.lowagie.text.documentexception;import Com.lowagie.text.font;import Com.lowagie.text.paragraph;import Com.lowagie.text.pdf.basefont;import Com.lowagie.text.pdf.pdfwriter;public class Pdfutil {public static void PrintPDF (String content) throws Documentexception,ioexception {Document document = new document (); Pdfwriter.getinstance (document, New FileOutputStream ("D:/demo.pdf"));//Basefont Chinese = basefont.createfont (" Stsong-light ",//" Unigb-ucs2-h ", basefont.not_embedded);//Use a font that comes with windows Basefont Chinese = basefont.createfont (" C:/ windows/fonts/simsun.ttc,1 ", Basefont.identity_h, basefont.embedded); Font font = new Font (Chinese, font.normal);d ocument.addauthor ("Westdream");d ocument.addtitle ("Test iText"); Document.addsubject ("This was an IText demo");d ocument.addkeywords ("iText keywords");d ocumeNt.addcreator ("Using iText");d ();d Ocument.add (new Paragraph (content, font));d ocument.close ();  public static void Main (string[] args) throws Exception {File File = new file ("C:\\users\\zan\\desktop\\demo.txt"); byte[] bytes = new byte[(int) file.length ()];inputstream input = new FileInputStream (file); (bytes, 0, (int) file.lengt H ());p rintpdf (New String (bytes, "GBK"));}}

Java output PDF

Related Article

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: 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.