I am trying to apply some javascript to a pdf to make it print silently. I found this chunk of code and pasted it in, but get the error below.
SyntaxError: missing ; before
statement 1: at line 2
This highlights the first 2 lines of the code below:
Document document = new Document();
FileOutputStream fos = new FileOutputStream("APP_PERSONAL.pdf");
Here’s the full code:
Document document = new Document();
FileOutputStream fos = new FileOutputStream("APP_PERSONAL.pdf");
try {
PdfWriter writer = PdfWriter.getInstance(document, fos);
document.open();
write.addJavaScript("this.print({bUI: false, bSilent: true, bShrinkToFit: true});",false);
write.addJavaScript("this.closeDoc();");
document.add(new Chunk("Silent Auto Print"));
document.close();
} catch (DocumentException e) {
e.printStackTrace();
}
I don’t know enough yet to understand where the missing semi-colon is. Does it mean it’s missing on the second line of code at the start of that line?
That’s Java, not Javascript.
This Java code will add the following Javascript code to a PDF file: