Expand my Community achievements bar.

SOLVED

How to add blank page at the end of the native pdf document using javascript in AEM Guides

Avatar

Level 2

Hi All,

I'm trying to create PDF document using AEM guides. i have frontcover, some topics and backcover in PDF. I need to add one blank page at the end of the pdf document using javascript. Is anyone having idea, how to achieve this?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi @Kiruthika_r ,

You can insert an empty div element at the end of the document and set the style property to page-break-before: always; See example below

var newPage = document.createElement("div");
newPage.setAttribute("style", "page-break-before: always;")
document.body.append(newPage);

You can add your custom logic around this code to achieve the desired result.

 

View solution in original post

8 Replies

Avatar

Employee

You can achieve this without JavaScript. What is the AEM version you are on?

Avatar

Level 2

I'm using AEM version 6.5.18.

Do you have any idea how to implement the blank page creation in PDF using javascript in AEM Guides?

Avatar

Employee

I meant to ask AEM Guides version, my bad. Can you please quickly share that?

Avatar

Employee

Thanks, @Kiruthika_r . Do the following in the Native PDF template editor.

  1. Create a page layout with no content or as you want the last blank page to be.
  2. Go to Settings > Page Layouts tab in the template.
  3. Clear the Back Page entry. You will find it at the bottom.
  4. Go to the Page Order tab
  5. Click + Add button
  6. Select the Back Page layout that you cleared in step 3 above, it will add at the bottom of the list.
  7. Click the + Add button again
  8. This time select the blank page layout you created in Step 1.
  9. Save the template
  10. Make sure you use this template in the native PDF output preset

You will find more details about page order here

Do let us know if you face any issues.

 

Thanks,
Vivek

Avatar

Level 2

Thanks, @VivekKumar. This solution is working fine for static logic. but I need to get the overall count pages in PDF. Based on the pdf page count, need to add blank pages dynamically using javascript in AEM Guides.

Avatar

Correct answer by
Employee

Hi @Kiruthika_r ,

You can insert an empty div element at the end of the document and set the style property to page-break-before: always; See example below

var newPage = document.createElement("div");
newPage.setAttribute("style", "page-break-before: always;")
document.body.append(newPage);

You can add your custom logic around this code to achieve the desired result.

 

Avatar

Level 2

Thanks @vikchand,

sorry for the delay in response. This code is working fine.