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

Weasyprint 0.41 generating PDFs that don't convert nicely to PNG #550

Closed
leohemsted opened this issue Dec 12, 2017 · 4 comments
Closed

Weasyprint 0.41 generating PDFs that don't convert nicely to PNG #550

leohemsted opened this issue Dec 12, 2017 · 4 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@leohemsted
Copy link

Hey, I've got a problem with weasyprint 0.41 where PDFs it generates have errors that make imagemagick break when trying to convert it to a PNG.

I've got a debian stretch docker container, and I call weasyprint inside it to generate a PDF, and then pass that PDF into imagemagick to create a png. imagemagick prints the following warning:

   **** Error reading a content stream. The page may be incomplete.
   **** Warning: Pattern stream has unbalanced q/Q operators (too many q's)

   **** This file had errors that were repaired or ignored.
   **** The file was produced by:
   **** >>>> WeasyPrint 0.41 (http://weasyprint.org/) <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

That's just a warning, it creates the image - however, it's an incomplete image, missing an embedded image from within the PDF. The PDF itself looks fine.

I've created a little test here:

Run the docker container, and grab the file out of it.

eg docker build . -t weasytest && docker run -it -v ~/dev/weasytest:/real-world -t weasytest cp letter.png /real-world/letter.png && open letter.png

And the resulting image doesn't have a logo. If we edit the dockerfile to pin weasyprint to 0.40, then the image renders fine with the logo.

Can anyone advise on things that might be going on here?

@liZe liZe added the bug Existing features not working as expected label Jan 4, 2018
@liZe liZe added this to the 43 milestone Jan 23, 2018
@liZe
Copy link
Member

liZe commented Jan 23, 2018

I've reproduced your error using cairo 1.14.x (stable) and <1.15.4 (unstable) versions, but not with cairo >=1.15.4. I suppose it's a subtle bug in cairo's PDF backend that's been fixed with cairo's huge changes about generated PDF files in 1.15.4.

I think that the bug was here from the beginning but is now triggered by the use of pdfrw since 0.41. As the bug is not triggered by other PDF readers (I've tried at least Google Chrome and Poppler's-based Evince), it may even be a bug in GhostScript (used by ImageMagick's convert).

Unfortunately, there's nothing I can easily do to fix that. Finding the root of the problem may take days, fixing it may take weeks, and having the fix upstream may take years (see #339 for example). Moreover, fixing cairo's stable branch when the unstable branch has already been fixed more than a year ago looks like a lot of wasted time 😢.

As always with cairo, the easy solution is to use the unstable version (it's not unstable, trust me 😉). Cairo 1.15.8 is packaged for Debian testing, installing it instead of 1.14.x will probably work as the API didn't change much.

@liZe
Copy link
Member

liZe commented Jan 23, 2018

Oh, there's another easy solution: you can use pdftoppm instead of convert to generate PNG files. It's in the poppler-utils package and should work pretty well if you don't rely on convert's other features.

(And it's cool to know that UK's government is using WeasyPrint to generate letters 😄.)

@liZe
Copy link
Member

liZe commented Mar 22, 2018

@leohemsted Can I do anything else for you?

@liZe
Copy link
Member

liZe commented Apr 21, 2018

@jonlesser I've found that a bug has been fixed about that in Ghostscript 9.21 (see #615). Feel free to reopen this issue if it doesn't fix your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants