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

png images are not reflected in pdf for ubuntu 16.04 #561

Closed
deepak-ace12 opened this issue Jan 18, 2018 · 15 comments
Closed

png images are not reflected in pdf for ubuntu 16.04 #561

deepak-ace12 opened this issue Jan 18, 2018 · 15 comments

Comments

@deepak-ace12
Copy link

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.

@liZe
Copy link
Member

liZe commented Jan 18, 2018

That's probably a duplicate of #556 😢. 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.

@deepak-ace12
Copy link
Author

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

@liZe
Copy link
Member

liZe commented Jan 18, 2018

but for linux, the comand doesn't mention the version of cairo...

You can have the version launching in your terminal: cairo-trace --version.

@liZe
Copy link
Member

liZe commented Jan 26, 2018

@deepak-ace12 Is the problem fixed for you?

@deepak-ace12
Copy link
Author

no..not yet

@liZe
Copy link
Member

liZe commented Feb 13, 2018

no..not yet

Could you please tell what cairo-trace --version gives in a terminal?

@cjwinchester
Copy link

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"])

@liZe
Copy link
Member

liZe commented Feb 23, 2018

Hello! Having the same/similar issue, except I can't get any images to render.

Then … it's probably not the same issue 😉.

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.

@cjwinchester
Copy link

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!

skyline
test.pdf

@liZe
Copy link
Member

liZe commented Feb 24, 2018

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?

@cjwinchester
Copy link

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.

@cjwinchester
Copy link

No luck. I'm managing four versions of Cairo with homebrew:

  • 1.14.10
  • 1.14.12
  • 1.15.8
  • 1.15.10

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?

@liZe
Copy link
Member

liZe commented Feb 24, 2018

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.

@cjwinchester
Copy link

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!

@liZe
Copy link
Member

liZe commented Feb 24, 2018

Thanks for helping me resolve!

@cjwinchester you're welcome!

@deepak-ace12 closing this issue, as your problem is probably due to your Cairo version.

@liZe liZe closed this as completed Feb 24, 2018
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