reportlab

Porting to Python3: PyPDF2 mergePage() gives TypeError

烂漫一生 提交于 2019-12-05 22:00:35
I'm using Python 3.4.2 and PyPDF2 1.24 (also using reportlab 3.1.44 in case that helps) on windows 7. I recently upgraded from Python 2.7 to 3.4, and am in the process of porting my code. This code is used to create a blank pdf page with links embedded in it (using reportlab) and merge it (using PyPDF2) with an existing pdf page. I had an issue with reportlab in that saving the canvas used StringIO which needed to be changed to BytesIO, but after doing that I ran into this error: Traceback (most recent call last): File "C:\cms_software\pdf_replica\builder.py", line 401, in merge_pdf_files

Bottle framework generate pdf

倾然丶 夕夏残阳落幕 提交于 2019-12-05 20:54:33
I need to generate PDF document using the Bottle framework. I tried similar to Django but that didn't work: @bottle.route('/pd') def create_pdf(): response.headers['Content-Type'] = 'application/pdf; charset=UTF-8' response.headers['Content-Disposition'] = 'attachment; filename="test.pdf"' from io import BytesIO buffer = BytesIO() from reportlab.pdfgen import canvas p = canvas.Canvas(buffer) p.drawString(100,100,'Hello World') p.showPage() p.save() pdf = buffer.getvalue() buffer.close() response.write(pdf) return response Bottle functions aren't supposed to return the response object, they're

How to create a PDF document with differing page sizes in reportlab, python

喜夏-厌秋 提交于 2019-12-05 18:30:03
问题 Is it possible to create a PDF document with differing page sizes in reportlab? I would like to create a document where the first page has a different size then the other pages. Can anyone help? 回答1: Yes, this should be possible, since PDF supports this, it's just a question of how to make it happen in ReportLab. I've never done this, but the following should work: c = reportlab.pdfgen.canvas.Canvas("test.pdf") # draw some stuff on c c.showPage() c.setPageSize((700, 500)) #some page size,

reportlab issue with line breaks using XPreformatted - additionall question mark printed

北城以北 提交于 2019-12-05 18:23:52
I'm using XPreformatted to print some preformated text and I have an issue with the line breaks. The line breaks are correctly translated but additionaly I get a "question mark" at the end of each line. This is my output: first line? second line? some more text I'm using django with mysql and the database field is a simple varchar field. I checked it in the database and everything what is between the "e" and the "s" in "first linE Second line" is a new line character. With new line character I mean what is entered in the database when I press "enter" ;-) Thus for me it seems strange that on

2 Axes Reportlab Graph

六月ゝ 毕业季﹏ 提交于 2019-12-05 13:53:48
I have managed to create a 2 axes graph in ReportLab, by overlapping a barchart and linepot. Here is the code for anyone interested in something similar: from reportlab.graphics.shapes import Drawing,colors from reportlab.graphics.widgets.markers import makeMarker from reportlab.graphics.charts.barcharts import VerticalBarChart from reportlab.graphics.charts.lineplots import LinePlot drawing = Drawing(400, 200) data = [(13, 5, 20, 22, 37, 45, 19, 4) ] noOfBars=len(data[0]) bc = VerticalBarChart() bc.x = 50 bc.y = 50 bc.height = 125 bc.width = 300 bc.data = data bc.valueAxis.valueMin = 0 bc

Pandas DataFrames in reportlab

六眼飞鱼酱① 提交于 2019-12-05 10:46:59
I have a DataFrame, and want to output it to a pdf. I'm currently trying to use ReportLab for this, but it won't seem to work. I get an error here: mytable = Table(make_pivot_table(data, pivot_cols, column_order, 'criterion')) make_pivot_table just returns a pivot table using pandas pivot_table function. The error I get is ValueError: <Table@0x13D7D0F8 unknown rows x unknown cols>... invalid data type My questions are: Is there any way to make reportlab work with DataFrames? If not, what package can I use for the same purpose? Py Hallo, I'm also needing to print as .pdf some Pandas DataFrame

What is the simplest way to add a hyperlink to a canvas element in ReportLab?

眉间皱痕 提交于 2019-12-05 08:52:05
I am using ReportLab to make a pdf using Python. I want to add a shape to the canvas, and have that shape act as a hyperlink. What is the simplest way to make the rectangle in the following example link to google.com? from reportlab.pdfgen import canvas from reportlab.lib.units import inch c = canvas.Canvas("hello.pdf") # move the origin up and to the left, draw square c.translate(inch,9*inch) # How do I make this rectangle link to google.com? c.rect(inch,inch,1*inch,1*inch, fill=1) c.showPage() c.save() Call linkURL on the Canvas: c.linkURL('http://google.com', (inch, inch, 2*inch, 2*inch),

How to position a python Reportlab table at position 10,100 and use drawString

≯℡__Kan透↙ 提交于 2019-12-05 07:06:07
问题 I am a python hobbyist and reportlab newbie. I know how to use drawString to put text at a particular place on a page, e.g.: c.drawString(10,100,"Welcome to Reportlab!") But I can't figure out how to place a table (which will only be a few lines long) so that the table begins at the same position as the c.drawString(10,100,"Welcome to Reportlab!"), which I will place elsewhere if I learn how to put my table there instead. I also can't figure out how to use drawString in the same script, since

How to open a generated PDF file in browser?

耗尽温柔 提交于 2019-12-04 22:16:26
问题 I have written a Pdf merger which merges an original file with a watermark. What I want to do now is to open 'document-output.pdf' file in the browser by a Django view. I already checked Django's related articles, but since my approach is relatively different, I don't directly create the PDF object, using the response object as its "file.", so I am kind of lost. So, how can I do is in a Django view? from pyPdf import PdfFileWriter, PdfFileReader from reportlab.pdfgen.canvas import Canvas from

IOError: “decoder zip not available” using matplotlib PNG in ReportLab on Linux, works on Windows

狂风中的少年 提交于 2019-12-04 20:57:14
问题 I'm using ReportLab to print a chart produced by matplotlib. I'm able to do this on my Windows development machine without trouble. When I deploy to a Ubuntu server, however, the rendering fails with the error described. I assume I'm missing a Python module, but I don't know which one. I believe the versions of Python, matplotlib, ReportLab and PIL are the same on both my development machine and the server. Code to convert the matplotlib figure (called chart) to PNG and return it: img_stream