I have the following situation.
I have a Main class in which I declared the standard public static void main(String[] args) method
Into the body of this main() method I am trying to call the following printPdf() declared into the Main class:
private void printPdf() {
/** The resulting PDF file: */
String result = "D:/SOFTLAB/massive_pdf_print.pdf";
// STEP 1 Creazione del documento in formato A4 e senza margini:
com.itextpdf.text.Document document = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4, 0, 0, 0, 0);
try {
/* STEP 2 Constructs a PdfWriter.
document: The PdfDocument that has to be written.
os: The OutputStream the writer has to write to
*/
PdfWriter.getInstance(document, new FileOutputStream(result));
// STEP 3:
document.open();
// STEP 4:
document.add(new Paragraph("Hello World!"));
// STEP 5:
document.close();
}catch (DocumentException ex){
ex.printStackTrace();
}
catch (IOException ex){
ex.printStackTrace();
}
}
To call it I do:
this.printPdf();
but I obtain the following error message: 'mainPkg.Main.this' cannot be referenced from a static context
So I think that it happens because the main() method is a static method but how can I correctly call my printPdf() method (that is declared in the same Main class that contains the main()) ?
Tnx