PDFBox setOpenAction to print

和自甴很熟 提交于 2021-02-09 20:44:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!