pisa with django and images

4,932 views
Skip to first unread message

ReneMarxis

unread,
Apr 6, 2009, 5:21:36 AM4/6/09
to Pisa XHTML2PDF Support
hello

i'm having problems using images on my developing machine (windows,
django 1.0.2 and all reportlabs/pisa newest versions).

Everything works great on the deployment machine but not in
developing.

I create the pdf with
pdf = pisa.pisaDocument(StringIO.StringIO( html.encode("ISO-8859-1")),
dest=result, path=path)

On production the images show up. On developing python hangs infinite.
The whole app just hangs and i need to kill the python process.

the path on developing is
print path
http://127.0.0.1:8000/apps/export/20/1

Could that port 8000 be the problem?

If i'm not passing in the path, pdf generation works ok even on
developing, but no images are displayed of course (nor css are used)

Someone else expirienced this kind of problem?

_thanks rene

twheeler

unread,
Apr 6, 2009, 1:28:35 PM4/6/09
to Pisa XHTML2PDF Support
Rene,
I am running into the same thing - or similar I am not getting any
images though..

I know it has to be a pathing issue. Is the path you are using abve
referring the html file or the images??



On Apr 6, 5:21 am, ReneMarxis <marxis.r...@googlemail.com> wrote:
> hello
>
> i'm having problems using images on my developing machine (windows,
> django 1.0.2 and all reportlabs/pisa newest versions).
>
> Everything works great on the deployment machine but not in
> developing.
>
> I create the pdf with
> pdf = pisa.pisaDocument(StringIO.StringIO( html.encode("ISO-8859-1")),
> dest=result, path=path)
>
> On production the images show up. On developing python hangs infinite.
> The whole app just hangs and i need to kill the python process.
>
> the path on developing is
> print pathhttp://127.0.0.1:8000/apps/export/20/1

ReneMarxis

unread,
Apr 7, 2009, 1:37:47 PM4/7/09
to Pisa XHTML2PDF Support
the image src="/site_media/logo.jpg" in the html file
http://127.0.0.1:8000/apps/export/20/1 is the path of the django
view, say the url i like to get as pdf.

But what about your python twheeler. Does it also hang?

twheeler

unread,
Apr 8, 2009, 11:26:00 PM4/8/09
to Pisa XHTML2PDF Support
Renee,
the code does not hang, I simply dont get any images.. you say the
path is the django view path, like from the URL conf?
so I am calling a helper to build and render the pdf - should my path
be the view that calls the helper...??

I am thinking the hanging issue you are seeing may be because of the
IP and port - do you also have issues with regular media??

as for css in the pdf I got this to work by doing something like
myCss = open(settings.DJANGO_SRC_PATH+"full_path _to_css","r").read()
then call pisaDocument passing it default_css = myCSS





On Apr 7, 1:37 pm, ReneMarxis <marxis.r...@googlemail.com> wrote:
> the image src="/site_media/logo.jpg" in the html filehttp://127.0.0.1:8000/apps/export/20/1 is the path of the django

twheeler

unread,
Apr 12, 2009, 10:31:55 PM4/12/09
to Pisa XHTML2PDF Support
renee,
have you had any luck?


On Apr 8, 11:26 pm, twheeler <thad.whee...@gmail.com> wrote:
> Renee,
>    the code does not hang, I simply dont get anyimages.. you say the

ReneMarxis

unread,
Apr 29, 2009, 5:57:10 PM4/29/09
to Pisa XHTML2PDF Support
Sorry for my late response...
No luck so far twheeler but i did not try much more any longer.
Focused on other things first. But i will have to investigate more on
this for sure.

On 13 Apr., 04:31, twheeler <thad.whee...@gmail.com> wrote:
> renee,
> have you had any luck?
>
> On Apr 8, 11:26 pm, twheeler <thad.whee...@gmail.com> wrote:
>
> > Renee,
> >    the code does not hang, I simply dont get anyimages.. you say the
> > path is the django view path, like from the URL conf?
Yes like from the url conf

> > so I am calling a helper to build and render the pdf  - should my path
> > be the view that calls the helper...??
I would say Yes
>
> > I am thinking the hanging issue you are seeing may be because of the
> > IP and port - do you also have issues with regular media??
No problem with regular media. everything works great.
And for me it's definitly hanging on developing when working with ip
and port. But it seems to be the right way to call pisa as i get the
images to show up this way on production (with django running in
apache and media beeing served from lighttpd)

>
> > as for css in the pdf I got this to work by doing something like
> > myCss = open(settings.DJANGO_SRC_PATH+"full_path _to_css","r").read()
> > then call pisaDocument passing it default_css = myCSS
Thanks for this. will try it out

Dirk Holtwick

unread,
May 4, 2009, 5:02:15 AM5/4/09
to xhtm...@googlegroups.com
Hi,

if you integrate images or CSS into your Django (or any other framework)
templates you should not rely on Pisa to get those data loaded via an
URL. Instead you should better point it directly to the files. E.g. in
your template you use the following image:

<img src='static/test.jpg'>

Then in your rendering code you should call somehow like this:

pdf = pisa.pisaDocument(in, out, path='/path/to/static/dummy')

Maybe there are issues with using absolute image paths in HTML. I'm also
not sure if you need to append 'dummy' to 'path' ('path' normally is the
full path to the HTML document, but on the server this is virtual, so we
do a little fake here).

Hope that helps
Dirk

ReneMarxis schrieb:

ReneMarxis

unread,
May 6, 2009, 12:55:53 AM5/6/09
to Pisa XHTML2PDF Support
Thanks Dirk

i'll try this out.

btw: great project :)
> >>>> the image src="/site_media/logo.jpg" in the html filehttp://127.0.0.1:8000/apps/export/20/1is the path of the django

ReneMarxis

unread,
Jun 6, 2009, 10:15:54 AM6/6/09
to Pisa XHTML2PDF Support
Hello Dirk
thanks for your answer.
Now this is how it works for me on my deployment machine (centos/
django/python 2.4)

#===Code
def test_view(request):
path = get_full_path_x(request)
pdf = pisa.pisaDocument(StringIO.StringIO( html.encode
("ISO-8859-1")), result, path=path)
return HttpResponse(result.getvalue(), mimetype='application/pdf')

def get_full_path_x(request):
full_path = ('http', ('', 's')[request.is_secure()], '://',
request.META['HTTP_HOST'], request.path)
return ''.join(full_path)
#===Code

However on my development machine (Windows XP) this does not work.
I don't know if you know django but in developing the application is
running with an internal webserver (coming with django) running on
port 8000.
And here my django application definitly hangs. I have to kill the
python.exe process.

Does someone else have any hint on how to get that running in
development?

On 4 Mai, 11:02, Dirk Holtwick <dirk.holtw...@gmail.com> wrote:
> >>>> the image src="/site_media/logo.jpg" in the html filehttp://127.0.0.1:8000/apps/export/20/1is the path of the django

ReneMarxis

unread,
Jun 7, 2009, 5:19:09 AM6/7/09
to Pisa XHTML2PDF Support
Ok. So now i got this working :)

here is how i did it:

def test_view(request)
import ho.pisa as pisa
html = render_to_string('test.html', { 'pagesize' : 'A4', },
context_instance=RequestContext(request))

result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO( html.encode
("ISO-8859-1")), dest=result, link_callback=fetch_resources )
return HttpResponse(result.getvalue(), mimetype='application/pdf')

def fetch_resources(uri, rel):
path = os.path.join(settings.MEDIA_ROOT, uri.replace
(settings.MEDIA_URL, ""))
return path

I allready tried that before but somehow the definition for MEDIA_ROOT
disapeared from my settings.py.
After adding it to the settings file css and images work production
and developing. Looks great now :)
Reply all
Reply to author
Forward
0 new messages