Let's create a simple method for generating a PDF file using JAVA.
Vamos criar um metódo simples para gerar um arquivo PDF utilizando JAVA.
public void createPDF() {
Document document = new Document(); // Create a new Document
try {
PdfWriter.getInstance(document, new FileOutputStream("path")); //Create a file
document.open(); //open file
document.add(new Paragraph("Write you text here")); //using string
/*Image image = Image.getInstance("path"); using image
document.add(image)
*/
} catch (DocumentException de) {
System.out.println(de.getMessage());
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
document.close();
}
Instead of writing with a fixed string you can use some variable in your code.
Ao invés de escrever as linhas pode utilizar alguma String em seu código.
string text = "Hello \n This is my text \n Thanks for read \n Bye Bye!!! \n"
document.add(new Paragraph(text)); //using string
It's very intuitive code, no secret, anything just comment.
É bem intuitivo o código, nenhum segredo, qualquer coisa só comentar.