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

Carl Karsten carl at personnelware.com
Wed Dec 2 11:53:32 EST 2009


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.

On Wed, Dec 2, 2009 at 10:41 AM, Dani Reguera <dreguera at tagzania.com> wrote:

>>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 <carl at personnelware.com>

>>

>> 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

>> _______________________________________________

>> reportlab-users mailing list

>> reportlab-users at lists2.reportlab.com

>> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

>

>

> --

>

> Dani Reguera

> dreguera at tagzania.com

>

> Tagzania Services [www.tagzania-services.com]

> Azitaingo Industrialdea 3 K

> E-20600 Eibar

> Tel: (+34) 943 82 17 80

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

>




--
Carl K


More information about the reportlab-users mailing list