Expand my Community achievements bar.

Printing to a particular printer

Avatar

Former Community Member
Hi

Is it posible to print to a particular printer?

/Ulf
Add topics

Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies

Avatar

Former Community Member
Yes, you can print to individual printers through either XFA or AcroForm. In XFA use the xfa.host.print() method. Which basically maps to the print method of the document. You could also do event.target.print()



The second would give you more control as you can retrieve the printer parameters using app.getPrintParams and this will be used by the print method as the new defaults.



To retrieve a list of printers you can use app.printerNames which returns an array of all printers installed on the client desktop. However, you are not able to find out the default printer (if you have switched previously) as Acrobat maintains a default per session - seperate from windows - as far as I know.

Avatar

Former Community Member
I used this script below but it does not work. How to make it work?



var objPrintParams = app.getPrintParams();



// Set so no dialog box is displayed at all to the user during printing

objPrintParams.interacitve = objPrintParams.constants.interactionLevel.silent;



// Select which printer to print to

objPrintParams.printerName = "HP DeskJet 970Cxi";



// Print only odd pages

objPrintParams.pageSubset = objPrintParams.subsets.odd;



// Print both content and comments

objPrintParams.printContent = objPrintParams.constants.printContent.docAndComments;



// Print the PDF using properties just set with printParams object

event.target.print(objPrintParams);

Avatar

Former Community Member
Made a few changes to your example and it works - except for printContent. I think printContent is always doc in designer as you cannot do a comment workflow on XFA-based forms



var objPrintParams = event.target.getPrintParams();



// Set so no dialog box is displayed at all to the user during printing

objPrintParams.interactive = objPrintParams.constants.interactionLevel.silent;



// Select which printer to print to

objPrintParams.printerName = "printer-name";



// Print only odd pages

objPrintParams.pageSubset = objPrintParams.constants.subsets.odd;



// Print the PDF using properties just set with printParams object

event.target.print(objPrintParams);

Avatar

Former Community Member
This is just what I was looking for except can the local printer name but changed to a shared network printer? For example,



// Select which printer to print to

objPrintParams.printerName = "\\server-name\printer-name";

Avatar

Former Community Member
Hi,



just wondering if there is a way of determining if the remote network printer exists.



I am using this:



try {

objPrintParams.printerName = "\\server-name\printer-name";

event.target.print(objPrintParams)

} catch(e) {

// does not get here if printer not found

app.alert(e);

}



where the printer has not been added to the list of printers on the local machine, I can print to that remote printer.



But, if the printer does not exist on the network, nothing happens and the print job does not proceed. No exceptions are thrown as shown above. Just wondering if there is a way to know if the remote network printer exists.



thanks for any assistance.

John