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 Clases; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileOutputStream; import java.io.IOException; /** * * @author davfer29 */ public class PDF { public static final String RESULT = "Users/davfer29/NetBeansProjects/DiarioFacilWeb/PDF"; Document documento = new Document(); FileOutputStream ficheroPdf; public void crearPDF(String filename, String nombre, String objetosComprados) throws DocumentException, IOException { // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 /* Image image1 = Image.getInstance("/Users/davfer29/NetBeansProjects/DiarioFacilWeb/build/web/images/client.png"); document.add(image1); image1.scaleAbsolute(150f, 150f);*/ //esto se usa para adjuntar imagenes al pdf y centrarlas document.addTitle("Bienvenido a DiarioFacil"); document.add(new Paragraph("Su compra de los articulos " + objetosComprados + " ha sido exitosa")); document.add(new Paragraph("Gracias! Agradecemos que haya elegido nuestra pagina " + nombre)); // step 5 document.close(); } }