Print all html content in pdf


#1

In my app i have to print a pdf from html, but it will print only the first page.
Here’s my code:

ipc.on('print-to-pdf', event => {
  const pdfPath = path.join(os.tmpdir(), 'temp.pdf')

  const win = BrowserWindow.fromWebContents(event.sender)

  win.webContents.printToPDF({marginsType: 1, pageSize:'Tabloid'}, (error, data) => {
    if (error) return console.log(error.message)

    fs.writeFile(pdfPath, data, err => {
      if (err) return console.log(err.message)
      shell.openExternal('file://' + pdfPath)
    })
  })
})

It could depends from the pageSize that i’m setting?


#2

I solved adding this to my css:

    > @media print {
    >   body {
    >     overflow: visible !important;
    >   }
    > }

Now my app print all html’s content, not only the first page