0

Different type of pdf files are generated using iText on the serverside and send over ResponsOutputStream. On the clientside, the printdialog is shown (at least on most viewer), and the defaultprinter is selected. Some pdfs should be printed on labelprinter, other on a desktopprinter. Is it possible to preselect a different printer when the printdialog shows up?

I've tried this for a desktop java application and it worked, but i'm not able to do this from serverside.

    ec.setResponseContentType("application/pdf"); 
    ec.setResponseHeader("Content-Disposition", "attachment; filename="labels.pdf"); 
    outStream = ec.getResponseOutputStream();
    writer = PdfWriter.getInstance(document, outStream);

    PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
    writer.setOpenAction(action);

same result using this instruction as I doesn't find a solution to preselect specific printer using Javascript

    writer.setOpenAction(PdfAction.javaScript("this.print(true);", writer));

the default printer or last used printer is always selected

  • Have you tried using the `printParams` argument of the `print` method and setting the `printerName` property therein to the client-side printer name? Cf. the [Adobe Acrobat SDK JavaScript™ for Acrobat® API Reference](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf). – mkl Jun 14 '19 at 14:40
  • TX a lot, this works like a charm – user2448443 Jun 18 '19 at 09:43
  • Great! I made this an actual answer instead of a mere comment; you can accept it by clicking the tick at its upper left, under the voting arrows. – mkl Jun 18 '19 at 10:29

1 Answers1

0

According to the Adobe Acrobat SDK JavaScript™ for Acrobat® API Reference the Doc method print also has a printParams parameter

printParams (optional, Acrobat 6.0) The PrintParams object containing the settings to use for printing. If this parameter is passed, any other parameters are ignored.

According to an example in that entry one can use this parameter to select a printer:

Example 2 (Acrobat 6.0)

Print current document to a known printer.

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "hp officejet d series";
this.print(pp);

Thus, if you know the client-side printer name, you can set it as demonstrated in this example.

PS: Most likely your code runs in a non-privileged context; thus, the pp.interactive will be ignored, you won't be able to trigger an automatic print job.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • indeed, I can't get it printed automatically, but being able to set the printername is allready a big improvement. – user2448443 Jun 19 '19 at 11:30