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

Print pages with JavaScript

Community Beginner ,
Nov 04, 2019 Nov 04, 2019

Hi everyone, I have a question. I have the script, that sorting pages depending size and i need to write a script to print pages - on different printers, depending on the page size (for example: A1, A2 etc.). May be somebody met this problem? 

 

my script: 

https://scrimba.com/c/c7PwMkua

TOPICS
How to , PDF forms , Print and prepress
14.9K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 05, 2019 Nov 05, 2019

You can use the alert method for that. For example:

 

if (app.alert("Do you want to print the file now?",2,2)==4) {

    this.print();

}

View solution in original post

Translate
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 ,
Nov 04, 2019 Nov 04, 2019

Look into the print method of the Document object and especially into the various properties of the PrintParams object.

Here's a simple example of how to print pages 1-5 to one printer and pages 6-10 to another:

 

 

var pp = this.getPrintParams();
pp.printerName = "My Printer 1";
pp.firstPage = 0;
pp.lastPage = 4;
this.print(pp);
pp.printerName = "My Printer 2";
pp.firstPage = 5;
pp.lastPage = 9;
this.print(pp);

 

Edit: Small mistake fixed in the code.

 

Translate
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 ,
Nov 04, 2019 Nov 04, 2019

Thank you so much, I'll try it!! 😉

Translate
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
Adobe Employee ,
Nov 05, 2019 Nov 05, 2019

Hi There,

 

Thanks for reporting this.

We provide a JavaScript tool inside Adobe Acrobat, which can be used to any additional content like page number on the PDF file.

 

Regards,

Swapnil Srivastava

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

Hi there. How can I bring up a modal window in Acrobat? I want that after sorting by page size, a modal window appears with a print request, if agreed, it should call the printer and plotter, depending on the size of the sheet. Somebody can advice me?

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

Are there in Acrobat JS Api command  - confirm() - like in native JS?

Translate
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
LEGEND ,
Nov 05, 2019 Nov 05, 2019

Do you have the JavaScript API Reference? It shows all classes and methods available. Specifically, app.alert, which is a whole lot easier than using Dialog.

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

Thanks, Yes dude I have a small JS Api reference, but i can't to find it. I'm junior in Adobe, therefore have many problem, but i'm trying. Thank you

Translate
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
LEGEND ,
Nov 05, 2019 Nov 05, 2019

The JavaScript API Reference isn't small - it's nearly 800 pages. You need it though. Here is a link to an old API Reference, but not much has changed lately... https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

You can use the alert method for that. For example:

 

if (app.alert("Do you want to print the file now?",2,2)==4) {

    this.print();

}

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

Yes dude, it works 🙂 I wrote: 

const requ = app.alert('Send to print?', 2, 2);
if(requ === 4){
const pp = this.getPrintParams();
pp.printerName = 'Printer1';
this.print(pp);
}

Translate
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 ,
Nov 05, 2019 Nov 05, 2019

Hello, can i do so? 

 

 

 

/* code for print pages:
   acp - is the array of objects, inside there are own width and height of every page in document */

if(app.alert('Do you want to print the files now?', 2, 2) == 4) {
    const pp1 = this.getPrintParams(),
          pp2 = this.getPrintParams();
    pp1.printerName = 'Printer';
    pp2.printerName = 'Plotter';
			
    for(var item = 0; item < acp.length; item++){
        if(acp[item].width <= 420 && acp[item].height <= 297){
            this.print(pp1);
        }
        if(acp[item].width >= 594 && acp[item].height >= 420){
            this.print(pp2);
        }
    }
}

 

 

 

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

- What is the "acp" array?

- Why are you using const instead of var?

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

Inside the acp array are objects of width and height pages. I usually use ES6, it will be problem in Adobe? 

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

Yes. The "const" keyword defines a constant, which means you can't change it.

Run this code and see what the results are:

const a = 5; a = 4; console.println(a);

And then run this code:

var b = 5; b = 4; console.println(b);

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

Also, you have to define the firstPage and lastPage parameters in the PrintParams object. If you don't, it will print the entire file by default.

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

I understand, thank you. But i need to print all the pages from the document, only they must be sorted. My code is sorting, i sent only a part of the code that will distribute the sorted pages to the printer and plotter. I'll change the const on var, but basically my code is working correctly?

Translate
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
LEGEND ,
Nov 06, 2019 Nov 06, 2019

If your code is working correctly, do you still have a question for us, please?

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

yes there will be questions, why do you ask?

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

I don't think your code is correct, as what you're doing in it doesn't make sense, but if you're happy with the result that's fine.

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

Want you print all pages on the printer and plotter?

Translate
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 ,
Nov 06, 2019 Nov 06, 2019

Yes, I want to make automatically process, after sort the pages i'll get modal window - print or not, when the user click - Yes - automatically print pages on plotter and printer depending sizes... Sorry for my english

Translate
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
LEGEND ,
Nov 06, 2019 Nov 06, 2019

So, what is your question. What does your code do now, please post the CURRENT code and tell us what it does, what you want it to do, and what is stopping you from doing this. Please never post code that is not the current exact code you are asking us to discuss, this wastes everyone's time.

Translate
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 ,
Nov 06, 2019 Nov 06, 2019
LATEST

Read the reply of try67:

Also, you have to define the firstPage and lastPage parameters in the PrintParams object. If you don't, it will print the entire file by default.

Translate
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
LEGEND ,
Nov 05, 2019 Nov 05, 2019

Look into the "Dialog" class. Complicated to use, but powerful.

Translate
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