Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing a page cuts off the contents halfway and does not continue on next page. #8351

Closed
dealvz opened this issue Jan 5, 2017 · 4 comments
Labels
blocked/need-info ❌ Cannot proceed without more information

Comments

@dealvz
Copy link

dealvz commented Jan 5, 2017

When I try to print a page that contains a large table and I use the printToPdf module, it gets cut off halfway and does not print a second page. Is there a workaround for this?

I'm essentially using the code from the electron examples, here it is. This specific print job is done in landscape mode:

ipcMain.on('printPage', (event, arg) => {
  const pageName = arg.pageName || 'print'
  const currentTime = new Date().getTime().toString()
  const pdfPath = path.join(os.tmpdir(), pageName + currentTime + '.pdf')
  const win = BrowserWindow.fromWebContents(event.sender)

  const landscape = arg.landscape || false
  win.webContents.printToPDF({ landscape }, function (error, data) {
    if (error) {
      // throw error
      console.log(error)
    }
    fs.writeFile(pdfPath, data, function (e) {
      if (e) {
        // throw e
        console.log(e)
      }
      shell.openExternal('file://' + pdfPath)
      event.sender.send('finishedPrinting', pdfPath)
    })
  })
})

This is what my web content looks like when I start the print job:

image

And this is what the print to pdf page looks like. As you can see, it is cut off and there is no second page:

image

@hokein hokein added the blocked/need-info ❌ Cannot proceed without more information label Jan 6, 2017
@hokein
Copy link
Contributor

hokein commented Jan 6, 2017

Could you provide the html file being print here? Please note that you should call print ToPDF API after webContents finishes load (did-finish-load) event, otherwise the print page maybe not completed.

@dealvz
Copy link
Author

dealvz commented Jan 6, 2017

Yea, everything is done after did-finish-load completes. Printing is done far into my app's life cycle.

The HTML is being generated by react. The html being printed is a modal, so there is also html in the background. However the modal spans the entire width and height of the page at the time of printing. Maybe something is going on with the other, non-modal-related, html on the page? However the same thing prints just fine using chrome and window.print().

I'd also like to point out that a similar issue occurs with Electron's Demos app in the printing example. In that example, the first page is printed just fine, but it cuts off and then the second page is completely blank. While the issue isn't exactly the same as the one im experiencing (since i'm not even getting a second page), they're similar enough that they might be related or caused by the same underlying issue.

Anyways, here's the modal html.

<div data-reactroot="" class="ReactModal__Overlay ReactModal__Overlay--after-open printOverlay">
    <div class="ReactModal__Content ReactModal__Content--after-open printContent" tabindex="-1" aria-label="BatchPrint">
        <table>
            <tbody>
                <tr>
                    <th>Date</th>
                    <th>Batch #</th>
                    <th>Teller</th>
                    <th>Loan #</th>
                    <th>Borrower</th>
                    <th>Amount</th>
                    <th>Payment Type</th>
                    <th>Bank Name</th>
                    <th>Check #</th>
                    <th>Routing #</th>
                    <th>Account #</th>
                </tr>
                <tr>
                    <td>1/5/2017 11:58:32 AM</td>
                    <td style="text-align: center;">12</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 11:50:07 AM</td>
                    <td style="text-align: center;">11</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 11:46:51 AM</td>
                    <td style="text-align: center;">10</td>
                    <td>teller</td>
                    <td>243458</td>
                    <td>JANE QUINONES</td>
                    <td>$254.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 11:12:10 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>566317</td>
                    <td>JANE DUMAS</td>
                    <td>$0</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 11:06:37 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>566317</td>
                    <td>JANE DUMAS</td>
                    <td>$261.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 10:58:36 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 10:48:36 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 10:44:05 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>761215</td>
                    <td>JANE PAGE</td>
                    <td>$360.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 10:08:05 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>243458</td>
                    <td>JANE QUINONES</td>
                    <td>$254.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 10:03:03 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>441445</td>
                    <td>JANE STUART</td>
                    <td>$171.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:50:44 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:46:38 AM</td>
                    <td style="text-align: center;">7</td>
                    <td>teller</td>
                    <td>255165</td>
                    <td>JANE SWEET</td>
                    <td>$361.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:42:42 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>837283</td>
                    <td>JOHN ANDRADE</td>
                    <td>$598.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:38:50 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>606220</td>
                    <td>JOHN MCMAHON</td>
                    <td>$144.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:31:57 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>307833</td>
                    <td>JOHN MCNEAL</td>
                    <td>$415.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:26:34 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>761215</td>
                    <td>JANE PAGE</td>
                    <td>$360.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:24:31 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>243458</td>
                    <td>JANE QUINONES</td>
                    <td>$254.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:22:28 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>500697</td>
                    <td>JOHN BETTS</td>
                    <td>$595.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:15:24 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>500697</td>
                    <td>JOHN BETTS</td>
                    <td>$595.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:14:08 AM</td>
                    <td style="text-align: center;">6</td>
                    <td>teller</td>
                    <td>315155</td>
                    <td>JOHN ROCHE</td>
                    <td>$105.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:11:49 AM</td>
                    <td style="text-align: center;">5</td>
                    <td>teller</td>
                    <td>566317</td>
                    <td>JANE DUMAS</td>
                    <td>$261.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:05:09 AM</td>
                    <td style="text-align: center;">4</td>
                    <td>teller</td>
                    <td>612659</td>
                    <td>JANE CERVANTES</td>
                    <td>$370.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 9:02:41 AM</td>
                    <td style="text-align: center;">3</td>
                    <td>teller</td>
                    <td>612659</td>
                    <td>JANE CERVANTES</td>
                    <td>$370.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 8:59:52 AM</td>
                    <td style="text-align: center;">2</td>
                    <td>teller</td>
                    <td>612659</td>
                    <td>JANE CERVANTES</td>
                    <td>$370.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 8:57:00 AM</td>
                    <td style="text-align: center;">1</td>
                    <td>teller</td>
                    <td>612659</td>
                    <td>JANE CERVANTES</td>
                    <td>$370.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
                <tr>
                    <td>1/5/2017 8:45:55 AM</td>
                    <td style="text-align: center;">1</td>
                    <td>teller</td>
                    <td>612659</td>
                    <td>JANE CERVANTES</td>
                    <td>$370.00</td>
                    <td>Cash</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

@dealvz
Copy link
Author

dealvz commented Jan 6, 2017

I ended up using a workaround since I couldn't get printToPdf to work properly.

I basically ended up using fs to write a custom html page to temp dir. In that html page, I call window.print() on load. After writing the html page to memory, I use shell.openExternal('file://' + filePath) to open the html file which is then opened by the user's default browser (in my case chrome). Then opening the html page causes the browsers print command to fire and it now prints just fine from chrome.

I guess it might be because of the format of the html itself but I don't have time to test it right now. Maybe if I created a new electron window with this html and then fired print from it, it would work.

image

@zcbenz
Copy link
Member

zcbenz commented Jun 6, 2017

I'm closing this since I can't reproduce this on v1.7.x.

@zcbenz zcbenz closed this as completed Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-info ❌ Cannot proceed without more information
Projects
None yet
Development

No branches or pull requests

4 participants