Hi,
I am trying to generate a pdf using weasyprint. I have installed everything as per the doc http://weasyprint.readthedocs.io/en/latest/install.html The pdf is working well on my mac system but when I am trying to deploy it on server (Ubuntu 16.04), the png images are not printed on the pdf file. Jpeg images are working just fine.
That's probably a duplicate of #556 :cry:. The bug is in Cairo 1.14.12, it's been fixed in Cairo's master branch but no new version has been released yet. The easy solution is to downgrade Cairo to 1.14.10.
but for linux, the comand doesn't mention the version of cairo...
sudo apt-get install build-essential python3-dev python3-pip python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0.0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
but for linux, the comand doesn't mention the version of cairo...
You can have the version launching in your terminal: cairo-trace --version.
@deepak-ace12 Is the problem fixed for you?
no..not yet
no..not yet
Could you please tell what cairo-trace --version gives in a terminal?
Hello! Having the same/similar issue, except I can't get _any_ images to render. I'm working from a Macbook Pro and running cairo-trace, version 1.15.10. Tried downgrading to 1.14.10 but no dice.
Rendering HTML via a Jinja template and handing that off to weasyprint for rendering: HTML(string=html).write_pdf(OUTFILE, stylesheets=["style.css"])
Hello! Having the same/similar issue, except I can't get any images to render.
Then … it's probably not the same issue :wink:.
I'm working from a Macbook Pro and running cairo-trace, version 1.15.10. Tried downgrading to 1.14.10 but no dice.
Do you have anything interesting in the logs? If you don't, I'd be interested in the HTML source and the generated PDF.
Hi, thanks for responding. Nothing in the logs. The HTML that gets generated is pretty extensive, but this bare-bones example does not render the image -- just the text. I've tried several different images of various types (jpg, png, gif, svg) but no luck.
Attached the image and the resulting PDF.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>skyline</title>
</head>
<body>
<img src="skyline.jpg" />
<p>Hello!</p>
</body>
</html>
Rendered to PDF like this:
from weasyprint import HTML
HTML(filename='test.html').write_pdf('test.pdf', stylesheets=["style.css"])
I don't have any image-related styling in my stylesheet. I'm running cairo 1.15.10. My project dependencies are:
cairocffi==0.8.0
CairoSVG==2.1.3
cffi==1.11.4
cssselect2==0.2.1
defusedxml==0.5.0
html5lib==1.0.1
Jinja2==2.10
MarkupSafe==1.0
pdfrw==0.4
Pillow==5.0.0
pycparser==2.18
Pyphen==0.9.4
python-dateutil==2.6.1
six==1.11.0
tinycss2==0.6.1
WeasyPrint==0.42.2
webencodings==0.5.1
Thanks for any insight you can offer!
It really looks like #556. Cairo 1.15.10 and 1.14.12 have this bug, but not 1.15.8, 1.14.10 or current master branch.
Tried downgrading to 1.14.10 but no dice.
Does it mean that you didn't manage to install 1.14.10 or that it didn't solve your problem?
I downgraded and it did not solve my problem. I'll try running the script against 1.14.10 again, and 1.15.8, and let you know the results.
No luck. I'm managing four versions of Cairo with homebrew:
For each version, I run brew switch cairo <version>, then the Python script. Same result: Text but no image on the resulting PDF.
Is there more information I could provide that would help debug?
Nothing in the logs.
Oh, I'm stupid. If you use WeasyPrint as a library, you have to configure logs like explained on this page and read what's in the logging file.
No luck. I'm managing four versions of Cairo with homebrew
Then it's something else. If it doesn't work, even with SVG files, then for some reason WeasyPrint can't find image files. You'll get more info in logs.
Aha! Missed that. Logged: Relative URI reference without a base URI: <img src="skyline.jpg">.
Adding __file__ to the HTML object did the trick: HTML(filename='test.html', base_url=__file__).write_pdf('test.pdf', stylesheets=["style.css"])
Thanks for helping me resolve!
Thanks for helping me resolve!
@cjwinchester you're welcome!
@deepak-ace12 closing this issue, as your problem is probably due to your Cairo version.
Most helpful comment
Aha! Missed that. Logged:
Relative URI reference without a base URI: <img src="skyline.jpg">.Adding
__file__to theHTMLobject did the trick:HTML(filename='test.html', base_url=__file__).write_pdf('test.pdf', stylesheets=["style.css"])Thanks for helping me resolve!