Weasyprint: Links do not render in PDF.

Created on 13 Mar 2013  路  11Comments  路  Source: Kozea/WeasyPrint

from weasyprint import HTML
HTML(string='<a href="http://google.com">link</a>').write_pdf('tmp.pdf')

Makes non-clickable links in PDF

Most helpful comment

I succeeded to upgrade Cairo and now I can click links. I found out that all lib files are in /usr/lib/x86_64-linux-gnu

All I did to install Cairo 1.16.0 is:

rm /usr/lib/x86_64-linux-gnu/libcairo* && \
wget -c https://cairographics.org/releases/cairo-1.16.0.tar.xz &&\
tar -xJf cairo-1.16.0.tar.xz && rm cairo-1.16.0.tar.xz

cd cairo-1.16.0/

./configure && make && make install && \
cp /usr/local/lib/libcairo* /usr/lib/x86_64-linux-gnu/

All 11 comments

This is a bug. Root cause: weasyprint.urls.get_link_attribute() always returns if the document has not base URL, but it should allow absolute URLs.

Fixed, thanks.

@SimonSapin the same thing appeared.

0.42.* works great but 44 (the last version at the moment) does not render clickable links in PDF

Clickable links require Cairo >= 1.15.4

@EugeneKovalev Any warnings logged? What's your Cairo version? What's your OS?

Sorry, I鈥檓 not actively working on WeasyPrint anymore. Consider filing a new bug with steps to reproduce, it鈥檒l have more visibility.

@Tontyna
OS - Ubuntu 18.10
Cairo - v1.14.8

Could you please tell me how to upgrade Cairo?
I have already tried to install the latest stable version. I ran ./configure, make, make install and it went to /usr/local/lib (seems to be OK)

But in python code when I run:

from cairocffi import cairo
print(cairo.cairo_version())

the output is 1.14.08


I also tried the solution from WeasyPrint docs:

sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info

Any thoughts?

Any thoughts?

Obviously the package repository isn't up-to-date. Since I dont know nothing about Ubuntu I have no idea how to get & install special versions of libraries.

I succeeded to upgrade Cairo and now I can click links. I found out that all lib files are in /usr/lib/x86_64-linux-gnu

All I did to install Cairo 1.16.0 is:

rm /usr/lib/x86_64-linux-gnu/libcairo* && \
wget -c https://cairographics.org/releases/cairo-1.16.0.tar.xz &&\
tar -xJf cairo-1.16.0.tar.xz && rm cairo-1.16.0.tar.xz

cd cairo-1.16.0/

./configure && make && make install && \
cp /usr/local/lib/libcairo* /usr/lib/x86_64-linux-gnu/

@EugeneKovalev's solution fixed cairocffi, but it broke Pycairo for me. I had to remove the cairo directory in my install, and to re-install it.

Hey, @Afoucaul
Did you manage to fix cairocffi and have your links to work without breaking Pycairo?

Hi @rjdebastiani, yeah I followed @EugeneKovalev's steps which fixed cairocffi, and then I uninstalled manually pycairo and re-installed it from pip.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mjbeyeler picture mjbeyeler  路  4Comments

jeffgabhart picture jeffgabhart  路  3Comments

zopyx picture zopyx  路  5Comments

bjornasm picture bjornasm  路  3Comments

thejasechen picture thejasechen  路  3Comments