pisa and image

148 views
Skip to first unread message

Hervé Edorh

unread,
Sep 22, 2009, 5:23:06 PM9/22/09
to Pisa XHTML2PDF Support
Hi, i am new in the usage of PISA. I have some problem to print
picture . I have read many things on internet and this how i have done
whose don't work

def test_view(request):
blog_entries = []

blog_entries.append({
'title':'Pisa 3.0.16 et dJango Template Engine',
'body': 'Hervé example..'
})
html = render_to_string('registration.html', { 'pagesize' :
'A4','title':'Pisa Hervé','blog_entries':blog_entries },
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

<html>
<head>

<style type="text/css">
@page {
size: {{ pagesize }};
margin: 1cm;

img{ zoom:80%; }


@frame footer {
-pdf-frame-content: footerContent;
bottom: 1cm;
margin-left: 1cm;
margin-right: 1cm;
height: 1cm;
}
}
</style>
</head>

<body>
<div>
{%block page_header%}
<div>

<p>seno</p>
<img src="/media/img/images.png" />
<h1>pisa html<span style="color: #FC0000;">to</
span>pdf documents</h1>
<h2>Python module for HTML/CSS to PDF conversion -
Ezpdf example</h2>
</div>
<hr />
{%endblock%}

{% for entry in blog_entries %}
<h2> {{ entry.title|upper }}</h2>
<p style="margin-left:15px">{{ entry.body }}</p>
{% endfor %}
</div>
<div id="footerContent">
<pdf:pagenumber>
</div>
</body>
</html>

the picture don't appear on the pdf file

Luc Saffre

unread,
Sep 23, 2009, 3:13:12 AM9/23/09
to xhtm...@googlegroups.com
Hervé,

Pisa doesn't find the picture's src url. I had success with something
like this:

url = settings.MEDIA_ROOT.replace('\\','/') + '/'
html = render_to_string('registration.html', { ...,
'MEDIA_URL':url} ...)

and then in your template, use:

<img src="{{ MEDIA_URL }}/img/images.png"/>

Maybe it is better to specify a size (in mm, other units seem to not work!)

<img src="{{ MEDIA_URL }}/img/images.png" width="30mm"/>

hth
Luc

Séno Hervé Edorh

unread,
Sep 23, 2009, 4:34:15 AM9/23/09
to xhtm...@googlegroups.com
Thank you Mr Luc, It's work


2009/9/23 Luc Saffre <luc.s...@gmail.com>



--
EDORH Hervé Séno
Développeur
Tel:(+221)775314948
Ma page:http://seno.edorh.com/
Dakar - Sénégal

geraldcor

unread,
Nov 12, 2009, 6:02:48 PM11/12/09
to Pisa XHTML2PDF Support
I am having a similar problem. Could you please post or email me your
settings.py segment for your MEDIA_URL and MEDIA_ROOT settings? I
tried doing everything that I could find on this list regarding images
and django, but I have not had success yet. I'm hoping viewing a
working setup may help me debug my own.

Thanks

Greg

On Sep 23, 1:34 am, Séno Hervé Edorh <senobo...@gmail.com> wrote:
> Thank you Mr Luc, It's work
>
> 2009/9/23 Luc Saffre <luc.saf...@gmail.com>

Séno Hervé Edorh

unread,
Nov 20, 2009, 11:28:46 AM11/20/09
to xhtm...@googlegroups.com
# Django settings for blog project.


import os.path
# url du projet
HERE_URL = 'http://127.0.0.1:8000'

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

DEFAULT_CHARSET='utf-8'

DEBUG = True

TEMPLATE_DEBUG = DEBUG
ADMINS = (
           ('Edorh', 'seno...@gmail.com'),
      )
MANAGERS = ADMINS

#DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.

#DATABASE_NAME = 'base.db' # Or path to database file if using sqlite3.

DATABASE_USER = '' # Not used with sqlite3.

DATABASE_PASSWORD = '' # Not used with sqlite3.

DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.

DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
# Local time zone for this installation. Choices can be found here:
# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
# although not all variations may be possible on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Europe/London'
# Language code for this installation. All choices can be found here:
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
# http://blogs.law.harvard.edu/tech/stories/storyReader$15

LANGUAGE_CODE = 'fr-FR'

SITE_ID = 1

      # If you set this to False, Django will make some optimizations so as not

      # to load the internationalization machinery.

USE_I18N = True

      # Absolute path to the directory that holds media.

      # Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '%s/media/' % PROJECT_PATH

       

      # URL that handles the media served from MEDIA_ROOT.   # Example: "http://media.lawrence.com"

MEDIA_URL = '%s/media/' % HERE_URL

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.request",
 # pour avoir MEDIA_URL dans les templates
    "django.core.context_processors.media",
    )
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
 # trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '%s/admn-media/'% HERE_URL
# Make this unique, and don't share it with anybody.
SECRET_KEY = '+vrg4srb(se4pufr6!x#39k7eui)2wu@sy)i!gn2w7-z+gzq3a'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
    # 'django.template.loaders.eggs.load_template_source',
    )
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
    )
ROOT_URLCONF = 'example.urls'
TEMPLATE_DIRS = (
    '%s/templates/' % PROJECT_PATH,
     )

#INSTALLED_APPS = (
    #'django.contrib.auth',
    #'django.contrib.contenttypes',
    #'django.contrib.sessions',
    #'django.contrib.sites',

    #)

geraldcor

unread,
Dec 15, 2009, 8:34:48 PM12/15/09
to Pisa XHTML2PDF Support
So back to an old frustration,

CSS works with the above method, but my images still don't show up.
When I dump the template via cgi.escape(html) I see the following
which should work as the CSS is working with this same method:
<img src="/home/idfl/webapps/media/images/GlobeLogo.png" width="100mm"
alt="IDFL - International Down and Feather Laboratory" />

I can not for the life of me figure out why this wouldn't work. I
tried a .jpg and that didn't work ether. Any ideas on why a seemingly
perfect absolute path would not work?

I am so close! Thanks for all of your help.

Greg

On Nov 20, 9:28 am, Séno Hervé Edorh <senobo...@gmail.com> wrote:
> # Django settings for blog project.
>
> import os.path
> # url du projet
> HERE_URL = 'http://127.0.0.1:8000'
>
> PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
>
> DEFAULT_CHARSET='utf-8'
>
> DEBUG = True
>
> TEMPLATE_DEBUG = DEBUG
> ADMINS = (
>            ('Edorh', 'senobo...@gmail.com'),
>       )
> MANAGERS = ADMINS
>
> #DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql',
> 'sqlite3' or 'ado_mssql'.
>
> #DATABASE_NAME = 'base.db' # Or path to database file if using sqlite3.
>
> DATABASE_USER = '' # Not used with sqlite3.
>
> DATABASE_PASSWORD = '' # Not used with sqlite3.
>
> DATABASE_HOST = '' # Set to empty string for localhost. Not used with
> sqlite3.
>
> DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
> # Local time zone for this installation. Choices can be found here:
> #http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATE...
> # although not all variations may be possible on all operating systems.
> # If running in a Windows environment this must be set to the same as your
> # system time zone.
> TIME_ZONE = 'Europe/London'
> # Language code for this installation. All choices can be found here:
> #http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
> #http://blogs.law.harvard.edu/tech/stories/storyReader$15

Luc Saffre

unread,
Dec 15, 2009, 11:18:42 PM12/15/09
to xhtm...@googlegroups.com
"/home/idfl/webapps/media/images/GlobeLogo.png" is a local file name. It
must be an URL, probably something like
"http://127.0.0.1:8000/media/images/GlobeLogo.png".
Looks like you are using MEDIA_ROOT where you should use MEDIA_URL.

Luc

On 16.12.2009 3:34, geraldcor wrote:
> So back to an old frustration,
>
> CSS works with the above method, but my images still don't show up.
> When I dump the template via cgi.escape(html) I see the following
> which should work as the CSS is working with this same method:
> <img src="/home/idfl/webapps/media/images/GlobeLogo.png" width="100mm"
> alt="IDFL - International Down and Feather Laboratory" />
>
> I can not for the life of me figure out why this wouldn't work. I
> tried a .jpg and that didn't work ether. Any ideas on why a seemingly
> perfect absolute path would not work?
>
> I am so close! Thanks for all of your help.
>
> Greg
>
> --
>
> Sie haben diese Nachricht erhalten, da Sie der Google Groups-Gruppe Pisa XHTML2PDF Support beigetreten sind.
> Wenn Sie Nachrichten in dieser Gruppe posten m�chten, senden Sie eine E-Mail an xhtm...@googlegroups.com.
> Wenn Sie aus dieser Gruppe austreten m�chten, senden Sie eine E-Mail an xhtml2pdf+...@googlegroups.com.
> Besuchen Sie die Gruppe unter http://groups.google.com/group/xhtml2pdf?hl=de, um weitere Optionen zu erhalten.
>
>
>

geraldcor

unread,
Dec 16, 2009, 11:22:36 AM12/16/09
to Pisa XHTML2PDF Support
Thank you for the response.

I switched to using MEDIA_URL and get http://idfl.webfactional.com/media/images/GlobeLogo.jpg
(changed it to a jpg just in case).

This did not work either. This is extremely confusing. Any other
thoughts? CSS works, why not images?

Greg
> > Besuchen Sie die Gruppe unterhttp://groups.google.com/group/xhtml2pdf?hl=de, um weitere Optionen zu erhalten.
>
>

Luc Saffre

unread,
Dec 16, 2009, 12:59:07 PM12/16/09
to xhtm...@googlegroups.com
Yes, this is now a valid URL. But there must be something wrong in your
Django or nginx configuration because this url returns a "404 Not Found"
page.

I looked at the HTML of http://idfl.webfactional.com/ssf/accounts/login/
and saw that http:...GlobeLogo.png *does* exist.

Seems that only the jpg version of the logo is missing.

Luc
> Besuchen Sie die Gruppe unter http://groups.google.com/group/xhtml2pdf?hl=de, um weitere Optionen zu erhalten.
>
>
>

geraldcor

unread,
Dec 16, 2009, 1:05:30 PM12/16/09
to Pisa XHTML2PDF Support
Ok, I just deleted the .jpg after I tried it out. Sorry. The png
version is there and it still doesn't work with the MEDIA_URL and the
new img src.

On Dec 16, 10:59 am, Luc Saffre <luc.saf...@gmail.com> wrote:
> Yes, this is now a valid URL. But there must be something wrong in your
> Django or nginx configuration because this url returns a "404 Not Found"
> page.
>
> I looked at the HTML ofhttp://idfl.webfactional.com/ssf/accounts/login/
> and saw that http:...GlobeLogo.png *does* exist.
>
> Seems that only the jpg version of the logo is missing.
>
> Luc
>
> On 16.12.2009 18:22, geraldcor wrote:
>
> > Thank you for the response.
>
> > I switched to using MEDIA_URL and gethttp://idfl.webfactional.com/media/images/GlobeLogo.jpg

Luc Saffre

unread,
Dec 16, 2009, 1:53:14 PM12/16/09
to xhtm...@googlegroups.com
Hmm, now I'm also stuck. No idea what else might go wrong. Sorry.
Luc
> Besuchen Sie die Gruppe unter http://groups.google.com/group/xhtml2pdf?hl=de, um weitere Optionen zu erhalten.
>
>
>

Reply all
Reply to author
Forward
0 new messages