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

Dynamic printing

Participant ,
Jan 13, 2022 Jan 13, 2022

 

Hi
I have a 111 page file.
Within this file I have several modules, and I would like to create a function that allows me to choose the print modes for each module
For instance:
The "MANDATE" form starts on page 5 and ends on page 9.
On page 5 I created a hidden field (named "Text1" with the custom calculation script "event.value = event.target.page;"
The number 4 appears in the field.
I did the same on page 9 where I inserted a new field (named "Text2") with the same script and the result that appears in the field is 8.
Then, again on page 5, I inserted a new field (named "MANDATE") with the custom calculation script var s1 = this.getField ("Text1"). Value;
var s2 = this.getField ("Text2"). value;
event.value = "[" + s1 + "," + s2 + "]";
The result is [4,8].
I did the same for the "INFO PRIVACY" module which goes from page 10 to page 15, for the "AV1" module which goes from page 16 to page 17, "AV2" from page 18 to page 19 and "AV3" from page 20 on page 21
So, I have the fields "MANDATO", "INFO PRIVACY", "AV1", "AV2", "AV3" with the results respectively [4,8], [9,14], [15,16], [17, 18], [19,20].
I created a button on page 4 of the pdf and added this function
var pp = this.getPrintParams ();
pp.colorOverride = pp.constants.colorOverrides.blackandwhite;
pp.pageHandling = pp.constants.handling.fit;
var s1 = this.getField ("MANDATE"). value;
var s2 = this.getField ("INFO PRIVACY"). value;
var s3 = this.getField ("AV1"). value;
var s4 = this.getField ("AV2"). value;
var s5 = this.getField ("AV3"). value;
pp.printRange = [s1, s2, s3, s4, s5];
pp.NumCopies = 1;
pp.DuplexType = 2;
pp.printerName = "Adobe PDF";
pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);

Obviously it doesn't work
Please, someone is able to solve this problem.
Thank you in advance for your help

TOPICS
JavaScript
1.4K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jan 14, 2022 Jan 14, 2022

> I have to abandon the function with pp.printRange, right?

 

No, you can create an array of arrays for this.

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 ,
Jan 14, 2022 Jan 14, 2022

Here's a simplified example of how it can work:

 

var s1 = Number(this.getField("Text1").value);
var s2 = Number(this.getField("Text2").value);
var s3 = Number(this.getField("Text3").value);
var s4 = Number(this.getField("Text4").value);

pp.printRange = [[s1,s2], [s3,s4]];

 

Remember, though, that the values you specify for printRange have to be zero-based, so if the values of these fields are 1-based you have to subtract 1 from them first.

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 ,
Jan 13, 2022 Jan 13, 2022

The printRange property takes a 2D array, with each array having two values: The start page for that range and the end page.

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
Participant ,
Jan 13, 2022 Jan 13, 2022

this means that in printRange I have to indicate the number of the start page and the end page? So to indicate the page of the beginning of printing or the page of the end of printing, can I not recall the data contained in a field?

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 ,
Jan 14, 2022 Jan 14, 2022

Sure you can. You can use either numbers or variables that have a Number value, but you have to do so in the correct format.

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 ,
Jan 14, 2022 Jan 14, 2022

You should read this:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/html2015/Acro12_MasterBook/JS_API_AcroJS...


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Jan 14, 2022 Jan 14, 2022

You can't use an array of strings for printRange.

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
Participant ,
Jan 14, 2022 Jan 14, 2022

So, I have to have to use this solution
var pp = this.getPrintParams ();
pp.colorOverride = pp.constants.colorOverrides.blackandwhite;
pp.pageHandling = pp.constants.handling.fit;
pp.firstPage = this.getField ("Text1"). value;
pp.lastPage = this.getField ("Text2"). value;
pp.DuplexType = 2;
pp.printerName = "Adobe PDF";
pp.interactive = pp.constants.interactionLevel.silent;
this.print (pp);

In the "Text1" field I have to insert the initial page and in "Text2" I have to insert the final page.
I have to abandon the function with pp.printRange, right?
Are there no alternatives?

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 ,
Jan 14, 2022 Jan 14, 2022

No, not at all.

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 ,
Jan 14, 2022 Jan 14, 2022

> I have to abandon the function with pp.printRange, right?

 

No, you can create an array of arrays for this.

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 ,
Jan 14, 2022 Jan 14, 2022

Here's a simplified example of how it can work:

 

var s1 = Number(this.getField("Text1").value);
var s2 = Number(this.getField("Text2").value);
var s3 = Number(this.getField("Text3").value);
var s4 = Number(this.getField("Text4").value);

pp.printRange = [[s1,s2], [s3,s4]];

 

Remember, though, that the values you specify for printRange have to be zero-based, so if the values of these fields are 1-based you have to subtract 1 from them first.

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
Participant ,
Jan 14, 2022 Jan 14, 2022
LATEST

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
New Here ,
Jan 14, 2022 Jan 14, 2022
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