Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package modelo; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; public class GeneratorPDF { public static void main(String[] args) { // criao do documento Document document = new Document(PageSize.A4, 72, 72, 72, 72); try { PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\Amanda\\Desktop\\teste.pdf")); document.open(); Font f = new Font(FontFamily.COURIER, 20, Font.BOLD); // adicionando um pargrafo no documento Paragraph p1 = new Paragraph("Gerando PDF - Java", f); p1.setAlignment(Element.ALIGN_CENTER); document.add(p1); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); } } /* document.newPage(); document.add(new Paragraph("Novo pargrafo na nova pgina")); Image figura = Image.getInstance("C:\\imagem.jpg"); document.add(figura); */