/** * Generates a simple 'Hello World' PDF file. * * @author blowagie */
public class HelloWorld {
/** * Generates a PDF file with the text 'Hello World' * * @param args no arguments needed here */ public static void main(String[] args) {
System.out.println("Hello World");
// step a: creation of a document-object Document document = new Document(); try { // step b: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document,new FileOutputStream("HelloWorld.pdf"));
// step c: we open the document document.open(); // step d: we add a paragraph to the document document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); }
// step e: we close the document document.close(); } }
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font FontChinese = new Font(bfChinese, 12, Font.NORMAL); Paragraph par = new Paragraph("世界你好",FontChinese) document.add(par);