[reportlab-users] Generate a Jpeg image from a PDF File done by reportlab

8 views
Skip to first unread message

Dani Reguera

unread,
Dec 2, 2009, 11:07:13 AM12/2/09
to For users of Reportlab open source software
Hi everybody,

I have a problem with a pdf file generated with reportlab, maybe anyone could help me. I have generated a file in reportlab, and now I want to make a thumbnail image, the format doesn't  matter (png or jpeg) and I'm trying with ghostscript (GS) and ImageMagick, but the problem is that GS tells me that it's and error. Seems that the pdf generated by reportlab is corrupted... could be that the pdf format is PDF-1.3?

Is in reportlab a way to generate a jpg image or export apdf file to a jpg image?

Any suggestion or help will be appreciated.

Dani






Carl Karsten

unread,
Dec 2, 2009, 11:31:17 AM12/2/09
to For users of Reportlab open source software

it is easier if you create files, but here is how I do it all in memory:

# get pdf
pdf = mkpdf(ds,sample=True)

# render pdf onto pixbuf
pixbuf = Pixbuf(COLORSPACE_RGB,False,8,286,225)
doc = poppler.document_new_from_data(pdf,len(pdf),password='')
page0=doc.get_page(0)
page0.render_to_pixbuf(0,0,8,11,1,0,pixbuf)

# save pixbuf as png
# There has to be a better way to get the image?
lst=[]
pixbuf.save_to_callback(lambda b,l: l.append(b), 'png', user_data=lst)
png=''.join(lst)

return png


http://bazaar.launchpad.net/~mdipierro/web2conf/devel/annotate/head%3A/controllers/badge.py#L68

Works, but that .join() bothers me. I think it is because I feel like
I am using string/char functions on bytes. which are the same thing,
mostly.. but... I have issues.


--
Carl K
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

Dani Reguera

unread,
Dec 2, 2009, 11:41:50 AM12/2/09
to For users of Reportlab open source software
>it is easier if you create files, but here is how I do it all in memory:


Hi Carl,

The pdf contents are images and text, but this images is generated by my. I have this images in my pc and only I put them in the canvas.

How could I do in a easier way?

Thx so much

2009/12/2 Carl Karsten <ca...@personnelware.com>



--

Dani Reguera
dreg...@tagzania.com

Tagzania Services [www.tagzania-services.com]
Azitaingo Industrialdea 3 K
E-20600 Eibar
Tel: (+34) 943 82 17 80

Robin Becker

unread,
Dec 2, 2009, 11:49:25 AM12/2/09
to For users of Reportlab open source software
........
we are using ghost script to make images out of pdfs and don't see these errors.
We rely on acrobat reader to tell us if the document is corrupt. If you have a
small script that creates the error please post it here.

The sort of command that we end up running looks like this

C:\Program Files\gs\gs8.60\bin\gswin32c.exe -q -dSAFER -dNOPAUSE -dBATCH
-dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dJPEGQ=85
-sOutputFile=C:\Tmp\talpha2-page%04d.jpg -sDEVICE=jpeg -r9x9 -f talpha2.pdf


--
Robin Becker

Carl Karsten

unread,
Dec 2, 2009, 11:53:32 AM12/2/09
to For users of Reportlab open source software
I think you misunderstood. it takes less code create the pdf as a
file: foo.pdf, and then convert that file to an image: foo.png.

that runs on a webserver. I didn't want to have to deal with write
permissions and multi user contention issues, so I keep the pdf and
png data in python vars. but it takes a few more lines of code,
including that .join() that makes me grumpy.

The code has been reviewed by a few people, and no one has suggested
there is anything wrong, so I am sure it is just fine. the comments
were more for anyone else that might know how to code it more
elegantly.

Floris van Manen

unread,
Dec 2, 2009, 12:07:03 PM12/2/09
to For users of Reportlab open source software
In svg you can create group objects using <g> </g> tags.
How do i do that for pdf using reportlab ?

thanks
F

Reply all
Reply to author
Forward
0 new messages