Skip to main content
niyetkhan
Known Participant
February 20, 2020
Answered

Add margins to page and select the specific printer

  • February 20, 2020
  • 1 reply
  • 4478 views

I am new in JavaScript.

I try to combine two scripts in one script, but without results. It is not working.

And here is the code:

/* Crop*/
var rCrop = this.getPageBox("Crop",this.pageNum);
rCrop[0] -= 8.5; // Adjust Left Side
rCrop[1] += 5.7; // Adjust Top Side
rCrop[2] += 0; // Adjust Right Side
rCrop[3] -= 0; // Adjust Bottom Side

this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Epson L805 Series";

 

This script should add margins to Left and Top Side of page, and select the specific printer.

What I 'm doing wrong?

This topic has been closed for replies.
Correct answer ls_rbls

I am using Windows 7, Acrobat 11 Pro.

I create new action, then in Extra Tools I select ''Run Java Script' and save the action with this code.


See page 33 of 48 , "Printing", of the Acrobat SDK  Javascript Samples Portfolio.pdf  here:  SDK 11    (uncompress the files to a directory that you want and navigate to that folder in 

 

 C:\Users\theUserAccountName\theFolderName\sdkDC_v1_win\Adobe\Acrobat DC SDK\Version 1\JavaScriptSupport

 

Also, you can try this script:

 

 

var rCrop = this.getPageBox("Crop",this.pageNum); 
rCrop[0] += 8.5; // Adjust Left Side 
rCrop[1] -= 5.7; // Adjust Top Side 
rCrop[2] -= 0; // Adjust Right Side 
rCrop[3] += 0; // Adjust Bottom Side 

this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);

var pp = this.getPrintParams();
pp.firstPage = this.pageNum;
pp.lastPage = this.pageNum;
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Epson L805 Series";

this.print(pp);

 

 

 

 

 

This script worked on my end but I don't have the same printing devices as you.

 

You must check that the printer name label in  pp.printerName = "Epson L805 Series";  is properly spelled and confirm that it matches with the actual printer. Also check in Windows what is the default printer set to in Control Panel, Devices and Printers

1 reply

ls_rbls
Community Expert
Community Expert
February 22, 2020

Hi,

 

You were missing the last line in your printing code which actually invokes the printing action.

 

See below:

var rCrop = this.getPageBox("Crop",this.pageNum); 
rCrop[0] += 8.5; // Adjust Left Side 
rCrop[1] -= 5.7; // Adjust Top Side 
rCrop[2] -= 0; // Adjust Right Side 
rCrop[3] += 0; // Adjust Bottom Side 
this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);

var pp = this.getPrintParams();
pp.interactive = pp.constants.interactionLevel.automatic;
pp.printerName = "Epson L805 Series";
this.print({bUI: false, nStart: this.pageNum})

 

niyetkhan
niyetkhanAuthor
Known Participant
February 22, 2020

Thank you for your response.

I'd like to ask you: is it possible in JS just to change (reset) the default printer, not to print?

 

P.S.: After running the script the printer was not changed to my specific printer (Epson L805). It was printed to default Adobe PDF printer.

ls_rbls
Community Expert
Community Expert
February 23, 2020

The printer name is correct.

The scripts works: it prints the page. But for my document I want only to change default printer (Adobe PDF) to the specific printer Epson L805.

Then after closing PDF document, the code must set default printer again.


Ok, I've been playing around with a few options but let me see if I understood you.

 

Your default pirnter is always set to "Adobe PDF" in MS Windows Control Panel--> Devices and Printers? OR, the document reverts itself  to Adobe PDF  after this print action is applied?

 

For example, as I don't have a physical printer installed in this PC, I've setup my default printer to "OneNote" for the purpose of this exercise. And the print action is set in the script to print to "Adobe PDF" (which in this case I am simulating with this script as if "Adobe PDF"  was your Epson printer).

 

So I see what you're saying.

 

The best answers that I could find to work around this printer setting from reverting or not reverting to defaults see here: 

 

https://answers.acrobatusers.com/Can-I-change-print-settings-actions-q274461.aspx

 

https://stackoverflow.com/questions/14752457/reset-printer-to-the-default-one-in-adobe-reader-javascript-api

 

Also, are you printing from a single local computer, OR, are you distributing this documents to other users that will be  accessing the  "Epson L805" through a print server in a local area network?