Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:02:13+00:00 2026-05-17T20:02:13+00:00

Related to: django – pisa : adding images to PDF output I’ve got a

  • 0

Related to: django – pisa : adding images to PDF output

I’ve got a site that uses the Google Chart API to display a bunch of reports to the user, and I’m trying to implement a PDF version. I’m using the link_callback parameter in pisa.pisaDocument which works great for local media (css/images), but I’m wondering if it would work with remote images (using a google charts URL).

From the documentation on the pisa website, they imply this is possible, but they don’t show how:

Normaly pisa expects these files to be found on the local drive. They may also be referenced relative to the original document. But the programmer might want to load form different kind of sources like the Internet via HTTP requests or from a database or anything else.

This is in a Django project, but that’s pretty irrelevant. Here’s what I’m using for rendering:

html = render_to_string('reporting/pdf.html', keys,
                        context_instance=RequestContext(request))
result = StringIO.StringIO()
pdf = pisa.pisaDocument(
        StringIO.StringIO(html.encode('ascii', 'xmlcharrefreplace')),
        result, link_callback=link_callback)
return HttpResponse(result.getvalue(), mimetype='application/pdf')

I tried having the link_callback return a urllib request object, but it does not seem to work:

def link_callback(uri, rel):
    if uri.find('chxt') != -1:
        url = "%s?%s" % (settings.GOOGLE_CHART_URL, uri)
        return urllib2.urlopen(url)
    return os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))

The PDF it generates comes out perfectly except that the google charts images are not there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:02:13+00:00Added an answer on May 17, 2026 at 8:02 pm

    Well this was a whole lot easier than I expected. In your link_callback method, if the uri is a remote image, simply return that value.

    def link_callback(uri, rel):
        if uri.find('chart.apis.google.com') != -1:
            return uri
        return os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
    

    The browser is a lot less picky about the image URL, so make sure the uri is properly quoted for pisa. I had space characters in mine which is why it was failing at first (replacing w/ ‘+’ fixed it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a food logging database in Django and I've got a query related
My Django templates use a lot of related stuff: images, style sheets, etc. Where
This question is related to (but perhaps not quite the same as): Does Django
For my Django app I have Events, Ratings, and Users. Ratings are related to
Related to https://stackoverflow.com/questions/139944/where-can-one-find-free-software-icons-images I have a need for free weather-related icons. Specifically, I need
I have two related models (one to many) in my django app and When
I took this sample code here : Django ORM: Selecting related set polls =
I have a django model and model form that look like this: -models.py class
I'm trying to use Django's annotate feature to add the count of a related
In Django, when I run manage.py test, I get a lot of authentication related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.