Problem showing images with Pisa

3,407 views
Skip to first unread message

somewhatofftheway

unread,
Apr 5, 2011, 7:44:12 AM4/5/11
to Pisa XHTML2PDF Support
Hi to all,

I have been tearing my hair out trying to get images to appear in a
PDF being generated from a (remote) web page. For some time I assumed
that this was due to the need to store images locally (I'm not sure if
this is still true).

Anyway, even now that images and css are stored locally, images do not
appear in the resulting PDF (although the CSS is apparently loaded).

I would appreciate any thoughts as to where I might go next with this
- Google searches have given nothing useful. Doing:

pisa.showLogging()


only gives an error message ('No handlers could be found for logger
'ho.pisa') - searching that seems to bring a whole new set of errors.

Could anybody point me in the right direction please?

Thanks

somewhatofftheway

unread,
Apr 5, 2011, 10:15:38 AM4/5/11
to Pisa XHTML2PDF Support
As an update to this in case it helps anybody, it seems that this is
to do with the code that sets image height and width. In pisa_tags.py
line 295:

if (width is None) and (height is not None):
factor = float(height) / img.drawHeight
img.drawWidth *= factor
img.drawHeight = height
elif (height is None) and (width is not None):
factor = float(width) / img.drawWidth
img.drawHeight *= factor
img.drawWidth = width
elif (width is not None) and (height is not None):
img.drawWidth = width
img.drawHeight = height

It seems that this does not like the height set (because it has 'px'
on the end). Fixing that however leads to further type errors. If I
delete the whole of the above code then I get a PDF I am happy with
(although presumably the heights and widths are incorrectly set).

samuele.mattiuzzo

unread,
Apr 5, 2011, 11:00:10 AM4/5/11
to Pisa XHTML2PDF Support
have you tried like in this post?

http://stackoverflow.com/questions/2179958/django-pisa-adding-images-to-pdf-output

fetch_resources callback could be what you need, works fine for me
with that!

Benjamin Sims

unread,
Apr 5, 2011, 11:34:53 AM4/5/11
to xhtm...@googlegroups.com, samuele.mattiuzzo
Yes, I did try that. The issue is not now with getting the images themselves, but with the fact that something in the parser is choking when trying to create the PDF - hence why it works if I delete that code.


--
You received this message because you are subscribed to the Google Groups "Pisa XHTML2PDF Support" group.
To post to this group, send email to xhtm...@googlegroups.com.
To unsubscribe from this group, send email to xhtml2pdf+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xhtml2pdf?hl=en.


samuele.mattiuzzo

unread,
Apr 5, 2011, 1:49:30 PM4/5/11
to Pisa XHTML2PDF Support
Do you set width and heigth using css? Maybe that's the problem, i had
the same issue (width: 100px), so i embedded all into the html
<img src="" width="100" heigth="100" /> and worked fine (if you have
lots of img classes generated via django, you have to explicit them
into the html)

On 5 Apr, 17:34, Benjamin Sims <benjamins...@gmail.com> wrote:
> Yes, I did try that. The issue is not now with getting the images
> themselves, but with the fact that something in the parser is choking when
> trying to create the PDF - hence why it works if I delete that code.
>
> On 5 April 2011 16:00, samuele.mattiuzzo <samum...@gmail.com> wrote:
>
>
>
> > have you tried like in this post?
>
> >http://stackoverflow.com/questions/2179958/django-pisa-adding-images-...

Benjamin Sims

unread,
Apr 8, 2011, 8:44:27 AM4/8/11
to xhtm...@googlegroups.com
I'm not using Django by the way - this is standalone, using Pisa as a library in a python script.

The width is indeed set using CSS. Changing it is not really a solution though (I can't change the original page).

Thanks for your help and tips - I think for now I will just delete the relevant code and let it be. If we go further with the project I will look at whether I can come up with a sensible patch.

Thanks,
Ben

matt.snider

unread,
Apr 14, 2011, 5:13:54 PM4/14/11
to Pisa XHTML2PDF Support
I'm also not seeing images in my PDFs. I'm using Boto and S3 to store
images. I see them just fine when I load the HTML manually in a
browser, but no images appears when I convert it to PDF (the non-image
CSS styles load just fine). I looked at the image tag function to see
if it was caused by the 'px' bug, and that didn't seem to be the
problem either. What steps should I pursue to debug this.

-matt

On Apr 8, 5:44 am, Benjamin Sims <benjamins...@gmail.com> wrote:
> I'm not using Django by the way - this is standalone, using Pisa as a
> library in a python script.
>
> The width is indeed set using CSS. Changing it is not really a solution
> though (I can't change the original page).
>
> Thanks for your help and tips - I think for now I will just delete the
> relevant code and let it be. If we go further with the project I will look
> at whether I can come up with a sensible patch.
>
> Thanks,
> Ben
>

Benjamin Sims

unread,
Apr 14, 2011, 5:35:46 PM4/14/11
to xhtm...@googlegroups.com
Well, I only solved it by liberal use of digging through the source code and the python debugger. Have you tried deleting the code that I did in order to see if it makes any difference?

Ben
Reply all
Reply to author
Forward
0 new messages