Help with correct way to print multiple HTML pages as PDF

Hi all,

I have this html/JS code that generates N tables based on user input. I’m trying to separate the content in pages of “A4” size and with no more that 6 tables within each page in order to give the option to print as PDF.

I’m using the built-in JS function window.print(). The issue is that when the browser opens up the printing preview window, only detects 2 pages and only first page content appears correct, the rest appears empty.

You can try for example to generate 24 tables (that would be 4 pages) and when click on print, only 2 pages are detected.

Basically, the main code is the highlighted in yellow to convert as PDF the content generated by the other 2 JS codes.

May someone help me to fix this issue in which I’m stuck. Thanks in advance

hello and welcome to fcc forum :slight_smile:

  • may be its because that document has an “empty” page in it, is it similar for other pdf documents as well?

happy coding :slight_smile:

Hello, the pages are not empty. Testing and testing, this is the updated code Edit fiddle - JSFiddle - Code Playground. Now if it detects the page but the content is scrolling down and a cut content appears and as a consequence, an extra page. If you want, you could test the shared link, entering for example 24, in the input form

but it only shows me “1 page” and no scrolling is in view or in effect

Please see this links Edit fiddle - JSFiddle - Code Playground

It will automatically ask how many tables want to generate. Enter for example 24, then click on print and you’ll see something like this: If you enter 24 should be 4 pages but appears 5 pages since there is a scroll down as pages go forward.

im still seeing that page from earlier :frowning: and not this as you have shared here…

Not sure what happens. Please check this link Edit fiddle - JSFiddle - Code Playground

Thanks for your answer. I’ve added break-after: always; and still pages brake wrong. What could be missing? This is the code so far Edit fiddle - JSFiddle - Code Playground

Hello, I will show you a website where you can easily convert your PDF files to others any format.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.