reportlab

Python reportlab save with canvas to specified location

点点圈 提交于 2021-02-19 04:41:33
问题 I am wondering how I can make my script save to the Desktop. Here's my code: from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter from reportlab.platypus import Image import csv import os data_file = "hata.csv" def import_data(data_file): inv_data = csv.reader(open(data_file, "r")) for row in inv_data: var1 = row[0] # do more stuff pdf_file = os.path.abspath("~/Desktop/%s.pdf" % var1) generate_pdf(variable, pdf_file) def generate_pdf(variable, file_name): c = canvas

Python reportlab save with canvas to specified location

筅森魡賤 提交于 2021-02-19 04:41:07
问题 I am wondering how I can make my script save to the Desktop. Here's my code: from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter from reportlab.platypus import Image import csv import os data_file = "hata.csv" def import_data(data_file): inv_data = csv.reader(open(data_file, "r")) for row in inv_data: var1 = row[0] # do more stuff pdf_file = os.path.abspath("~/Desktop/%s.pdf" % var1) generate_pdf(variable, pdf_file) def generate_pdf(variable, file_name): c = canvas

Properly add page numbers and total number of pages to PDF using ReportLab

泄露秘密 提交于 2021-02-18 18:15:12
问题 I am trying to create a document that has page numbering of the format "Page x of y". I have tried the NumberedCanvas approach (http://code.activestate.com/recipes/576832/ and also from the forums https://groups.google.com/forum/#!topic/reportlab-users/9RJWbrgrklI) but that conflicts with my clickable Table of Contents (https://www.reportlab.com/snippets/13/). I understood from this post http://two.pairlist.net/pipermail/reportlab-users/2002-May/000020.html that it may be possible using forms

Increase dpi in matplotlib chart without changing it's size

筅森魡賤 提交于 2021-02-11 14:31:51
问题 I'm trying to create a pdf using Python's reportlab module. I generated a png with matplotlib and saved it in the pdf file using report labs canvas.drawImage method. My problem is that the generated png file is very fuzzy. I specified the size in inches with plt.figure(figsize=(20,10)) and saved the picture with the plt.savefig method. This works out perfectly (except the fuzzy quality of the picture). But when I increase the dpi within the savefig method the size of the picture increases. Is

ReportLab Django Not Rendering Chinese Characters

家住魔仙堡 提交于 2021-02-08 10:25:03
问题 I'm having difficulty making ReportLab render Chinese Characters. From everything I've looked up people are saying that it is probably a font problem but I've used a lot of different fonts and it doesn't even seem to be using them at all. The Chinese characters always just come out as black squares. Below is some sample code of what I have. # -*- coding: utf8 -*- from reportlab.lib.pagesizes import letter from reportlab.pdfbase.ttfonts import TTFont from io import BytesIO pdfmetrics

rendering a ReportLab pdf built from SimpleDocTemplate

元气小坏坏 提交于 2021-02-06 10:43:09
问题 I've a got a django app that currently generates pdfs using a canvas that the user can download. I create a StringIO buffer, do some stuff and then send call response.write. # Set up response response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=menu-%s.pdf' % str(menu_id) # buffer buff = StringIO() # Create the pdf object p = canvas.Canvas(buff) # Add some elements... then p.showPage() p.save() # Get the pdf from the buffer and return the

rendering a ReportLab pdf built from SimpleDocTemplate

耗尽温柔 提交于 2021-02-06 10:42:07
问题 I've a got a django app that currently generates pdfs using a canvas that the user can download. I create a StringIO buffer, do some stuff and then send call response.write. # Set up response response = HttpResponse(mimetype='application/pdf') response['Content-Disposition'] = 'attachment; filename=menu-%s.pdf' % str(menu_id) # buffer buff = StringIO() # Create the pdf object p = canvas.Canvas(buff) # Add some elements... then p.showPage() p.save() # Get the pdf from the buffer and return the

Add figure and tables list to Table of Content using reportlab

此生再无相见时 提交于 2020-12-15 04:29:46
问题 I am latest reportlab and django, and standard platypus TOC with the notify to 'TOCEntry' works great for my document. I am now trying to add 2 more sections to Table of Contents: 'List of Figures', and 'List of Tables'. Since the flowables h1, h2, table, image etc. in the document can occur in any order, I cannot seem to separate the 2 lists from the main TOC. Ideally I would like to have something like: Table of Content: Heading1 Sub1 Sub2 Heading2 Sub3 Sub4 Sub5 List of Figures: Figure1

Generate PDF from HTML using Django and Reportlab

只谈情不闲聊 提交于 2020-12-01 07:33:05
问题 I am coming back with a new question which I am unable to answer, having scratched my head the whole day on it. I want to generate a PDF from a webpage by clicking on a "Download PDF" button. I tried several modules including Reportlab and XHTML2PDF but I am not able to generate any pdf nor downloading it... Here is what I did with Reportlab, following Render HTML to PDF in Django site - - views.py - - import cStringIO as StringIO import ho.pisa as pisa from django.template.loader import get