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
  • 4466 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.

Markarius
Inspiring
February 24, 2020

You can create a list of all available printers:

var l = app.printerNames.length;
for ( var i = 0; i < l; i++)
  console.println("(" + (i+1) + ") " + app.printerNames[i]);

Bernd_Alheit,

is this code only for Windows?  doesnt seem to be working in MacOS...