Condition section does not work

Hello, I want a blank page to be added when the pages are odd, but even though the designer appears correct in both the print test and Outputpreset, a blank page is always added in all cases.
I have used a postpagination script, is there another way to do it?

Hello @Frederick,

It is not possible to enable or disable Print Sections by a Post Pagination Script. Please use a Control Script to disable or enable a Print Section instead.

As an alternative you can apply something like the following as Post Pagination Script instead:

  • Name: Example
  • Selector: #example
let printSections = merge.context.sections;
let totalPageCount = 0;

for (let i = 0; i < printSections.length; i++) {
	let currentPageCount = 0; //printSections[i].pagination.pageCount;
	
	if (printSections[i].enabled) currentPageCount = printSections[i].pagination.pageCount;
	
	totalPageCount += currentPageCount;
	
	if (i + 1 == printSections.length) {
		if (totalPageCount % 2 == 1) {
			printSections[i].minPages = currentPageCount + 1;
			merge.section.paginate();
		}
	}
}

Important: Applying the above JavaScript code won’t result in the expected behaviour when the option “Duplex” is checked in the Sheet Configuration settings of one of the Print Sections.

Tip: Notice that I’m using #example instead of body as Selector. The reason why I’m targeting an (unique) element that does only exist on the last Print Section rather then using body is because otherwise the Post Pagination Script gets executed as many times as there are Print Sections.

The above JavaScript code will retrieve the total page count of all Print Section and will add an extra blank page to the last section i + 1 == printSections.length when the total page count is odd (totalPageCount % 2 == 1).

[Edited 1: Changed the order of the text and changed a number of words]
[Edited 2: Updated the JavaScript code to make sure that disabled Print Sections are ignored]

Hello, thanks for the help, how and where do I insert the #example element in the last section?
thank you.

You can just add an empty <p>-element* at the end of the Source code of your last Print Section or you can check if you have an element that only exists on your last Print Section and use this element as selector.

*An example of an empty <p>-element:

<p id="example">
	<br>
</p>

Tip: Make sure that you’re using an unique id, in case of adding an empty <p>-element.

Hello, perfect, add a page at the end of the odd invoices.
But I have 2 questions, let’s see if you can help me solve them.
The first is that the page counter resets in each section, in a 3 page invoice the first section, which is always a page, is correct, it says 1/3, but in the second section it says 2/4, 3/4, 4/4.
The second question is if I can make the added page appear without the data of the master page, so that it always appears blank.

Thank you very much again.
greetings.

Hello, I have already resolved the issue of the master page not being applied to the last page.
I guess that’s correct?

  • printSections[i].sheetConfig.positions.single.masterFront = undefined; works as long as the Print Section in question consist of one pages.
  • printSections[i].sheetConfig.positions.last.masterFront = undefined; works as long as the Print Section in question consists of two pages.

I expect that the following JavaScript code:

if (totalPageCount % 2 == 1) {
	printSections[i].minPages = currentPageCount + 1;
	merge.section.paginate();
}

Needs to be change to the following JavaScript code in this case:

if (totalPageCount % 2 == 1) {
	currentPageCount++;

	printSections[i].minPages = currentPageCount;

	if (currentPageCount > 1) {
		printSections[i].sheetConfig.positions.last.masterFront = undefined;
	} else {
		printSections[i].sheetConfig.positions.single.masterFront = undefined;
	}

	merge.section.paginate();
}

Important: Please keep in mind that in both cases the solution won’t work when the option “Duplex” is checked in the Sheet Configuration settings of one of the Print Sections.