Shiva Kumar
Shiva Kumar

Reputation: 33

PDFBox setOpenAction to print

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);

Upvotes: 3

Views: 1252

Answers (2)

JAVAC
JAVAC

Reputation: 1270

try this PDActionJavaScript("this.print({bUI: false, bSilent: true, bShrinkToFit: true});");

Upvotes: 2

Tilman Hausherr
Tilman Hausherr

Reputation: 18861

You can do this without JS:

    PDActionNamed action = new PDActionNamed();
    action.setN("Print");
    doc.getDocumentCatalog().setOpenAction(action);

Upvotes: 3

Related Questions