1
Good afternoon, I created a PDF.java, which has the function of generating a pdf, and in another file (Formulariohotelerioscontroller.java) when clicking on a certain button, I urge the PDF.java file to be able to generate and open the pdf, however, I need that when I click on the button that finds itif in Formulariohotelerioscontroler.java, redeem Edittext’s values located in it, and then print the results in the PDF. Thank you!!
FILE THAT GENERATES THE PDF:
public class Pdf {
public static final String IMAGE = "imagens/boleto.png";
public static final String DEST = "results/images/boleto.pdf";
public static void main(String[] args) throws IOException, DocumentException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new Pdf().createPdf(DEST);
}
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document(PageSize.A4.rotate());
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfContentByte canvas = writer.getDirectContentUnder();
Image image = Image.getInstance(IMAGE);
image.scaleAbsolute(PageSize.A4.rotate());
image.setAbsolutePosition(0, 0);
canvas.addImage(image);
document.close();
Desktop.getDesktop().open(new File("results/images/boleto.pdf"));
}
}
FILE CALLING INSTANCE PDF.AJVA WHEN CLICKING BUTTON:
@FXML public void gerarPdf(){
try {
Pdf.main(null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Your question is confused, one more thing confuses me even more: does your code have two main classes? Why Javafx Creates a Main Class and a Controller.
– Gustavo Fragoso
hello Gustavo, I did not understand your remark, two classes with main?
– Vinicius Colutti
I am trying to rescue filled values in an Edittext, located in the file that instantiates the pdf to be generated. And then present them in the generated pdf.
– Vinicius Colutti
Its PDF class has a public Static void main(String[] args) and the javafx main class has another public Static void main(String[] args) { Launch(args); }
– Gustavo Fragoso
I understood, but it prevented me from accomplishing the enlightened?
– Vinicius Colutti
From the point of view of programming is incorrect.
– Gustavo Fragoso