reportlab

How to set any font in reportlab Canvas in python?

守給你的承諾、 提交于 2019-11-27 20:00:01
问题 I'm using reportlab to create pdfs. When I try to set a font using the following method, I get a KeyError : pdf = Canvas('test.pdf') pdf.setFont('Tahoma', 16) But if I use 'Courier' instead of 'Tahoma' there isn't a problem. How can I use Tahoma? 回答1: Perhabs Tahoma is a TrueType font, and you need to register it first. According to the user guide of ReportLab you need to do this: from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont pdfmetrics.registerFont

Transparency in PNGs with reportlab 2.3

空扰寡人 提交于 2019-11-27 17:15:48
问题 I have two PNGs that I am trying to combine into a PDF using ReportLab 2.3 on Python 2.5. When I use canvas.drawImage(ImageReader) to write either PNG onto the canvas and save, the transparency comes out black. If I use PIL (1.1.6) to generate a new Image, then paste() either PNG onto the PIL Image, it composits just fine. I've double checked in Gimp and both images have working alpha channels and are being saved correctly. I'm not receiving an error and there doesn't seem to be anything my

loading matplotlib object into reportlab [duplicate]

爱⌒轻易说出口 提交于 2019-11-27 16:17:39
This question already has an answer here: Is there a matplotlib flowable for ReportLab? 5 answers I'm trying to load a matplotlib object into reportlab. Here is my code: from reportlab.pdfgen import canvas from reportlab.lib.utils import ImageReader from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Image from matplotlib import pyplot as plt def __get_img_data(): """ returns the binary image data of the plot """ img_file = NamedTemporaryFile(delete=False) plt.savefig(img_file.name) img_data = open(img_file.name + '.png', 'rb').read() os.remove(img_file.name) os.remove(img

Python- Reportlabs - save 2 different graphs in 2 different pages?

我怕爱的太早我们不能终老 提交于 2019-11-26 23:23:45
问题 I've the following code where I'm drawing a vertical bar graph and a line graph as well inside a PDF. How do I save these 2 graphs in 2 different pages of the PDF. I saw that it can be done using - c = canvas.Canvas("hello.pdf") hello(c) c.showPage() c.save() But, instead of using Canvas, I'm using Drawing object in which showPage() method does not exist. How do I save the 2 graphs in 2 different pages of the PDF? Right the second graph(line chart) overlaps the first graph (vertical bar chart

Is there a matplotlib flowable for ReportLab?

☆樱花仙子☆ 提交于 2019-11-26 22:25:06
I want to embed matplotlib charts into PDFs generated by ReportLab directly - i.e. not saving as a PNG first and then embedding the PNG into the PDF (i think I'll get better quality output). Does anyone know if there's a matplotlib flowable for ReportLab? Thanks Here's a solution using pdfrw: #!/usr/bin/env python # encoding: utf-8 """matplotlib_example.py An simple example of how to insert matplotlib generated figures into a ReportLab platypus document. """ import matplotlib matplotlib.use('PDF') import matplotlib.pyplot as plt import cStringIO from pdfrw import PdfReader from pdfrw.buildxobj

loading matplotlib object into reportlab [duplicate]

空扰寡人 提交于 2019-11-26 18:35:29
问题 This question already has an answer here: Is there a matplotlib flowable for ReportLab? 5 answers I'm trying to load a matplotlib object into reportlab. Here is my code: from reportlab.pdfgen import canvas from reportlab.lib.utils import ImageReader from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Image from matplotlib import pyplot as plt def __get_img_data(): """ returns the binary image data of the plot """ img_file = NamedTemporaryFile(delete=False) plt.savefig(img