pisa

CSS not rendered by Pisa's pdf generation in Django

余生颓废 提交于 2020-01-12 21:52:13
问题 I generate a pdf file from HTML using Pisa: def fetch_resources(uri, rel): path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, "")) return path def write_pdf(template_src, context_dict, filename): template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = open(filename, 'wb') pdf = pisa.pisaDocument(StringIO.StringIO( html.encode("UTF-8")), result, link_callback=fetch_resources) result.close() My HTML has a link to an

Unable to load images/files pisa pdf Django python

扶醉桌前 提交于 2020-01-03 05:06:10
问题 I had a problem before where it wouldn't show Chinese characters even when I specified @font-face to use a UTF-8 font. It turns out I cannot display images as well... so I seems like I am unable to get any of the files embeded into my pdf. This is the code I use: def render_to_pdf(template_src, context_dict): """Function to render html template into a pdf file""" template = get_template(template_src) context = Context(context_dict) html = template.render(context) result = StringIO.StringIO()

django - pisa : adding images to PDF output

萝らか妹 提交于 2019-12-17 05:50:11
问题 I'm using a standard example from the web (http://www.20seven.org/journal/2008/11/pdf-generation-with-pisa-in-django.html) to convert a django view / template into a PDF. Is there an "easy" way to include images (either from a url or a reference on the server) in the template so they will show on the PDF? 回答1: I got the images working. the code is as follows: from django.http import HttpResponse from django.template.loader import render_to_string from django.template import RequestContext

Python module Pisa: how change background color for all page?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 17:24:00
问题 How i can change background color of all page? like this : body,div { background-color:#f4f4f4; } Now background changes only for div with information, remaining page have white color. if it is possible, can you write example? P.s. How i can draw border around ? 回答1: Acording to the documentacion https://github.com/chrisglass/xhtml2pdf/blob/master/doc/usage.rst#supported-page-properties-and-values @page only accept few css propierties: background-image size margin, margin-bottom, margin-left,

Using Pisa to write a pdf to disk

回眸只為那壹抹淺笑 提交于 2019-12-13 11:37:41
问题 I have pisa producing .pdfs in django in the browser fine, but what if I want to automatically write the file to disk? What I want to do is to be able to generate a .pdf version file at specified points in time and save it in a uploads directory, so there is no browser interaction. Is this possible? 回答1: Yes it is possible. for example, using code from Greg Newman as a starter: from django.template.loader import get_template from django.template import Context import ho.pisa as pisa import

Save chartkick chart as image or in pdf using python, flask and pisa/ xhtml2pdf

自古美人都是妖i 提交于 2019-12-12 02:32:45
问题 My app is in python using the flask framework. I have a chart that I've generated with chartlink. I'd like to include it on a pdf that I'm outputting with pisa. Is this possible? Is there some way to save the chartkick chart as an image? Or should I look into another chart-generating option like pygal or matplotlib? 回答1: According to the chartkick documentation you can give users the option to download an image of the chart. You will have to include canvg before chartkick.js. Another option

How to set the width of the page?

…衆ロ難τιáo~ 提交于 2019-12-11 05:11:27
问题 I have been trying to increase the width of pdf but nothing seems to work: <style type="text/css"> @page { size: a4 landscape; width: 27cm; /* not working */ @frame content { top: 2cm; width: 27cm; /* not working */ margin-left: 1.5cm; /* changing these values work!! */ margin-bottom: 2cm; /* changing these values work!! */ } } </style> No matter what I try, the content width doesn't seem to increase. All my <div> , <tables> are at 100%, and reducing the margin increases the size of the table

No handlers could be found for logger “xhtml2pdf”

不羁岁月 提交于 2019-12-10 18:08:49
问题 I'm using xhtmltopdf.pisa for generating pdf from html template. The code was working fine. pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources, default_css=open(pdf_css_path, 'r').read()) But some times I noticed that, the above code is not working. The error threw was No handlers could be found for logger "xhtml2pdf" . Only some times I can find this error, but other times just works fine. Any help is appreciated. 回答1: The reason for

Pisa (XHTML -> PDF) in Django will not display images in PDF

萝らか妹 提交于 2019-12-10 06:18:26
问题 To start, I've seen the other threads on this, and I have tried nearly everything to try to fix this but... When using Pisa to render an HTML page to PDF, the images in said HTML go conspicuously missing. That is to say, when the page is rendered to HTML, everything is just dandy, but when I switch the output to PDF using Pisa, the images disappear. The most common thing I've found to do is to create a link callback function thus: def fetch_resources(uri, rel): path = os.path.join(settings

Pisa and lastPage

感情迁移 提交于 2019-12-08 03:26:11
问题 Greetings, I'm using PISA to generate some nice pdf of my web pages. Anyway I'd need to put a footer div -only- in the last page of the pdf document. I found the tag "@page lastPage" in the official documentation but I can't make it work. I show you some of my code: <style type="text/css"> @page { size: {{ pagesize }}; margin: 1cm; margin-bottom: 5.6cm; margin-top: 7cm; @frame header { -pdf-frame-content: headerContent; top:1cm; margin-left: 1cm; margin-right: 1cm; height:6.5cm; } @frame