[reportlab-users] Generate a Jpeg image from a PDF File done by reportlab
Carl Karsten
carl at personnelware.com
Wed Dec 2 11:31:17 EST 2009
On Wed, Dec 2, 2009 at 10:07 AM, Dani Reguera <drbakhache at gmail.com> wrote:
> 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.
>
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
More information about the reportlab-users
mailing list