Professional Documents
Culture Documents
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
PdfContentByte cb = escribir.getDirectContent();
// define el tipo de letra
BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250,
BaseFont.NOT_EMBEDDED);
// establece el tamao de la letra
cb.setFontAndSize(bf, 20);
// inicia la ubicacion del texto en el documento
cb.beginText();
//nombre
cb.setTextMatrix(80, 530);
cb.showText("Nombre: " + txtNombre.getText());
//apellido
cb.setTextMatrix(80, 500);
cb.showText("Apellido: " + txtApellido.getText());
//telefono
cb.setTextMatrix(80, 470);
cb.showText("Telefono: " + txtTelefono.getText());
cb.endText();
File path = new File ("C:/Users/pas/Desktop/java/pascualito.pdf");
Desktop.getDesktop().open(path);
documento.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(pdf.class.getName()).log(Level.SEVERE, null, ex);
} catch (DocumentException | IOException ex) {
Logger.getLogger(pdf.class.getName()).log(Level.SEVERE, null, ex);
}
}