python-3.xgoogle-cloud-platformxhtml2pdfpisa

python 3: Using pisa for creating pdf with multiple image urls in html content, rendering images incorrectly


I am trying to create pdf in my google cloud function using python 3 : pisa to create pdf. There are multiple imgage urls in my html content to be rendered in pdf, But the images in pdf are rendering anywhere in the pdf. For ex : I have 4 img tags in my html with 4 different image urls (which are stored in google cloud storage), but single image is showing at all 4 places , sometimes 2 images are displayed at different places. On Each code run, the result might be different.

Here is my code to create pdf:

from xhtml2pdf import pisa

def make_PDF(html):
  packet = BytesIO()
  pisa.CreatePDF(html, dest = packet)
  result = packet.getvalue()
  return result

Solution

  • Revert it to the old version xhtml2pdf==0.2.11. The latest version of xhtml2pdf has an issue with rendering images.