问题
I'm new to PDFBox, I have a requirement to send the PDF to the printer when it is opened. We are using PDFBox api to generate the PDFs. I have used the below code to try setting the action on open but nothing worked. Please help. I have used different javascript like window.print(); this.print(); print();
PDDocument doc = new PDDocument();
PDActionJavaScript javascript=new PDActionJavaScript("app.print();");
doc.getDocumentCatalog().setOpenAction(javascript);
回答1:
try this PDActionJavaScript("this.print({bUI: false, bSilent: true, bShrinkToFit: true});");
回答2:
You can do this without JS:
PDActionNamed action = new PDActionNamed();
action.setN("Print");
doc.getDocumentCatalog().setOpenAction(action);
来源:https://stackoverflow.com/questions/33282522/pdfbox-setopenaction-to-print