• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Add margins to page and select the specific printer

Community Beginner ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript

Views

3.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 22, 2020 Feb 22, 2020

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;
...

Votes

Translate

Translate
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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})

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

Are you using macOS or Windows?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

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-javasc...

 

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 22, 2020 Feb 22, 2020

Copy link to clipboard

Copied

My default pirnter is always set to "Adobe PDF" in MS Windows Control Panel--> Devices and Printers and I am printing from a single local computer.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2020 Feb 23, 2020

Copy link to clipboard

Copied

MODIFIED REPLY

 

NOTE:   I AM NOT ABLE TO USE THE REPLY BUTTON ON THIS PAGE ANY MORE BUT THE REPLY EDIT REPLY WORKS

 

This answer is in response to Markarius.

 

The  pp.printName is a feature that only works on Micrososft Windows, not in macOS.

 

See here:  " Set or get the name of destination printer. The printerName property is a Windows-only
feature; currently, the destination printer cannot be set through this property on the Mac.
By default, printerName is set to the name of the default printer. If set printerName
to an empty string the default printer will be used. When printerName is an empty
string and fileName is a nonempty string, the current document is saved to disk as a
PostScript file. See Example 2 below.
See also app.printerNames. "

 

This is referenced in the Adobe JavaScript Scripting Reference on page 300.

 

Well, after some more reading and testing the following four lines below also works on my end. 

 

 

 

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

 

 

 

 

Unless I 've misunderstood your question, I'm not having the same issue that you're describing.

 

After I print using the script, I save  and close the PDF.

 

Then I re-open it, and if I click on print using the file menu in Acrobat it seems to retain the last printer used (which is whatever I put in the script for the pp.printerName line.  It doesn't list my MS Windows default printer as the first option from the dropdown menu.

 

See line number 2 in the script above. If you prefer, you may want to use pp.interactive = pp.constants.interactionLevel.full;  instead of automatic  interaction level. 

 

Using automatic interaction level in full  will bring up the Save As and Print user interface dialogue boxes while the script executes.

 

 In addition to be able to select a different printer soon after the cropping  part of the script executes, it's convenient because you can  interact with the script actions on the fly, like for example, assign a new file name, see any errors during the process, and specify a different folder location to save the PDF.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2020 Feb 23, 2020

Copy link to clipboard

Copied

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]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 23, 2020 Feb 23, 2020

Copy link to clipboard

Copied

Bernd_Alheit,

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2020 Feb 24, 2020

Copy link to clipboard

Copied

LATEST

The code is for Windows and MacOS.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines