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

"html2pdf__page-break" gives unexpected vertical left aligned line #2

Closed
alundiak opened this issue May 3, 2017 · 17 comments
Closed

Comments

@alundiak
Copy link

alundiak commented May 3, 2017

@eKoopmans not sure if this is an issue (yours or jsPDF) or designed feature.

My HTML

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js"></script>
    <script src="lib/html2canvas.min.js"></script>
    <script src="lib/html2pdf.js"></script>
</head>
<body>
     <div id="element-to-print">
        <span>I'm on page 1!</span>
        <div class="html2pdf__page-break"></div>
        <span>I'm on page 2!</span>
    </div>
    <script type="text/javascript" src="./index.js"></script>
</body>
</html>

So having this

<span>I'm on page 1!</span>
<div class="html2pdf__page-break"></div>
<span>I'm on page 2!</span>

WITH NO custom CSS code gives me a hint I would expect just text on 2 pages.

My JS:

var element = document.getElementById('element-to-print');
const options = {
    margin: 10,
    filename: pdfFileName,
    image: {
        type: 'jpeg',
        quality: 0.98
    },
    html2canvas: {
        dpi: 192,
        letterRendering: true
    },
    jsPDF: {
        orientation: 'portrait'
    }
}

html2pdf(element, options);

Soch code gives me PDF, and I see some vertical line in content.
This is how Chrome PDF viewer shows:
screen shot 2017-05-03 at 20 43 05

screen shot 2017-05-03 at 20 43 11

And this is how Adobe Reader on MacOS shows:
screen shot 2017-05-03 at 20 43 22
screen shot 2017-05-03 at 20 43 30

Left aligned from the text, and among whole pages I see vertical line, presumably left-broder, etc.

@eKoopmans will u agree with me, that my expectation TO NOT have that line does at least some sense?

@eKoopmans
Copy link
Owner

Yep, that looks like a problem! I'll look into it.

@lidijarad
Copy link

lidijarad commented May 12, 2017

Hi @eKoopmans thank you for your library, I found a similar error, and this happened if I changed the margin != 1. If margin is set to 1, then the output is ok. I just checked and this seems to happen if I change any of the values that you provide in your example in the README.

@eKoopmans
Copy link
Owner

Hi @alundiak @lidijarad, I'd definitely like to resolve this issue but I haven't yet been able to reproduce it. It could be a platform thing. Could you please:

  1. Create a fork of this jsFiddle that illustrates the issue (the dependencies are already included in the fiddle), and
  2. Tell me what browser, OS, and PDF viewer you're using?

Thanks!

@alundiak
Copy link
Author

@eKoopmans
This jsFiddle example uses your repo js files via raw access. And result file.pdf is with vertical lines and black region.

html2canvas 0.5.0-beta4
jspdf/1.3.4/jspdf.debug.js

I also tried with https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.jswhich is in fact beta-3 - result the same.

file (1).pdf

@eKoopmans
Copy link
Owner

Hi, as I mentioned in the readme, html2pdf works best with the custom builds of html2canvas and jsPDF included in the /vendor/ directory. Specifically here, the black bars are caused by an html2canvas issue with offscreen rendering, which is resolved in the custom build in /vendor/.

The jsFiddle I linked uses the /vendor/ files for both dependencies. Here's a fiddle with your code in it, the result for me doesn't produce any black bars.

@alundiak
Copy link
Author

ok, then close this issue, if it's not an issue.

@alundiak
Copy link
Author

alundiak commented May 12, 2017

I think it's bug, because as an end consumer, I want to use 3rd party libs and not depend on your own build of the lib code. Otherwise such lib is not well maintainable. When new version/release of html2canvas appear, u will update ur repo and I will have to update my code with file from your repo directly. I would like to install by npm or bower module/component and rely on it strictly from official releases.

@eKoopmans
Copy link
Owner

@alundiak I hear you, I'd rather be able to use the stock versions too, but right now that offscreen rendering issue is an unavoidable bug in html2canvas. There's no way I could fix it from the outside. I'm waiting on the pull request to be merged in over there, as soon as it is then there will be no need for custom builds!

Your initial issue, with the dark vertical strip to the left of the text, seems separate from the black boxes, and I'd still like to resolve it. Have you tested with the custom html2canvas?

@alundiak
Copy link
Author

html2canvas issue with offscreen rendering, which is resolved in the custom build in /vendor/

If u did changes in minified file, then I would suggest u add comment on header of file, so that code researcher realize, that minified file IS NOT the same version as version published on CDN or elsewhere. Doing this, u will show, the reason why u have copy of file in code itself. U know - if I saw it in code, I would know why u have copy. Yes I read it in readme, and I realise the reason of copy in vendor. But hope u agree, that from code perspective, it's not informative, that 3rd-party library has been somehow changed.

@eKoopmans
Copy link
Owner

You're right @alundiak, I've added info about the custom builds to both vendor dependencies in 474b36e.

@alundiak
Copy link
Author

alundiak commented May 13, 2017

@eKoopmans this is "html2pdf usage - NEW" jsfiddle.
It uses:

Results is the same:
file_May-13-2017_.pdf

MacOS 10.12.4, Chrome 58.0, Safari 10.1, Firefox 53.0.2

Adobe Acrobat Reader

Architecture: x86_64
Build: 17.9.20044.222436
AGM: 4.30.69
CoolType: 5.14.5
JP2K: 1.2.2.38123

@eKoopmans
Copy link
Owner

You're going to say this isn't obvious - and you'd probably be right - but again as mentioned in the readme, the order of the dependencies is important.

jsPDF includes an out-of-date version of html2canvas internally, so you need to include html2canvas after jsPDF and before html2pdf. I've updated the order of the includes in your fiddle (the only change I made is including html2canvas before html2pdf instead of after).

Maybe it would be best to package all of the dependencies together with Browserify and offer a html2pdf.bundle.js to avoid all of these sorts of issues. In any case, please try the link I sent and let me know if it's still producing the black bars or boxes (neither show up for me).

@alundiak
Copy link
Author

@eKoopmans :) I tried, and the reality of JS proves that all works fine now. Silly, but have to admit. One bundle would be great.

@eKoopmans
Copy link
Owner

Agreed, I'll make a bundle (and NPM package info etc) in the near future. Thanks for helping track down this problem!

@lidijarad
Copy link

lidijarad commented May 14, 2017

@eKoopmans, I have updated the order in which I load the files and am using your modified versions of the other libs and the output of the pdf seems to be good now. Thank you so much for tending to this so promptly.

@eKoopmans
Copy link
Owner

No problem @lidijarad! I'm glad everything's working well, let me know if you run into any other problems.

@eKoopmans
Copy link
Owner

Btw, bundle was added in v0.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants