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

  • Home
  • SEARCH
  • 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 7602483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:25:23+00:00 2026-05-30T23:25:23+00:00

I was having trouble exporting images in an html file as pdf, a similar

  • 0

I was having trouble exporting images in an html file as pdf, a similar solution exists here.

The html is being rendered properly on the server. I verified it by cross checking it on a url.

but while trying to download/render the pdf **i get a pdf but which is blank, also it says error in the third line of the download function in views.py

Here is what i tried:

html file:

<html>
<head>
<link href="{{ STATIC_URL }}css/certificate.css" rel="stylesheet"
  type="text/css" />
</head> 
<body>
<div class="certificate_container">
    <div class="statictext">
        <p>{{ name }}</p>
    </div>
</div>
</body>
<html>

css file:

body{margin:0px; padding:0px;}
.certificate_container{ width:792px; height:612px; background:url("../images/certificate.gif") no-repeat;}
.statictext{width:400px; margin:0px auto; padding-top:240px; height:30px; text-align:center; font:bold 14px Arial, Helvetica, sans-serif; color:#333;}

views.py:

#relevant imports
from reportlab.pdfgen import canvas
import xhtml2pdf.pisa as pisa
import cStringIO as StringIO

def download(request):
    html = render_to_string("certificate.html", { 'pagesize' : 'A4', }, context_instance=RequestContext(request))
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(), dest=result, link_callback=fetch_resources )
    if not pdf.err:
        return HttpResponse(result.getvalue(), mimetype='application/pdf')
    return HttpResponse('Gremlins ate your pdf! %s' % cgi.escape(html))

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


def home(request):
    return render(request, 'certificate.html', {'name':'user1'} )

The urls have been taken care of properly.

  • 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-30T23:25:25+00:00Added an answer on May 30, 2026 at 11:25 pm

    I later found, this could not be achieved using the above tech stack, hence i tried getting a template image and used PIL to modify it based on context. And that worked.

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

Sidebar

Related Questions

Having trouble with an .htaccess file on WAMP. Works on the live server, but
I'm having a bit of trouble exporting a csv file that is created from
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
Having trouble understanding how to filter an images table by tag information in a
I am having trouble exporting my java project from eclipse as a jar executable
I'm having trouble setting up a new server using Moonshine and Capistrano. It seems
I'm having trouble with Soundcloud.php on my server. Although it runs just fine on
I'm having some trouble figuring out, why my triangle is not rendered at the
I'm having trouble expiring a cookie in php. here's my code: <?php setcookie('reitinvestor_user', 'null',
I'm exporting a grid with NPOI v1.2.3, and am having trouble getting cell formatting

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.