1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; public class HelloWorld { /** Path to the resulting PDF file. */ public static final String RESULT = "hello.pdf"; public static void main(String[] args) throws DocumentException, IOException { new HelloWorld().createPdf(RESULT); } public void createPdf(String filename) throws DocumentException, IOException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); document.add(new Paragraph("Hello World!")); document.close(); } } |