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 8717937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:24:48+00:00 2026-06-13T06:24:48+00:00

The file will not display until the whole file is loaded. How can i

  • 0

The file will not display until the whole file is loaded. How can i display the progress in browser?

from io import BytesIO
from reportlab.pdfgen import canvas
from django.http import HttpResponse

def some_view(request):
     # Create the HttpResponse object with the appropriate PDF headers.
     response = HttpResponse(mimetype='application/pdf')
     response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'

     buffer = BytesIO()

     # Create the PDF object, using the BytesIO object as its "file."
     p = canvas.Canvas(buffer)

     p.drawString(**, **, "Hello world.") # draw pdf, size > 10M

     # Close the PDF object cleanly.
     p.showPage()
     p.save()

     # Get the value of the BytesIO buffer and write it to the response.
     pdf = buffer.getvalue()
     buffer.close()
     response.write(pdf)
     return response
  • 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-06-13T06:24:51+00:00Added an answer on June 13, 2026 at 6:24 am

    Well, in your example I think it would be pretty simple (and almost instantaneous). You would just print out/return a progress indicator for drawString, showPage, etc. Assuming the actual PDF you’re generating is more involved, you could use the setProgressCallBack method of the BaseDocTemplate class. Of course, this would require that you use the reportlab platypus engine.

    There are a few methods/properties of note (see the comments), let’s say you have a custom template class which overrides BaseDocTemplate:

    from reportlab.platypus import BaseDocTemplate
    
    class MyDocTemplate(BaseDocTemplate):
        """Override BaseDocTemplate for "progress bar" information"""
    
        def __init__(self, *args, **kwargs):
            BaseDocTemplate.__init__(self, *args, **kwargs)
            # BaseDocTemplate keeps a "progress" dictionary for its own
            # internal use, which is updated as various drawings are done.
            # This directs reportlab to use your own custom method
            # as the "callback" function when updates are made.
            # Notice the use of the __ prefix for the method, which ensures
            # that it calls *your* custom class's method, and not the default.
            # Should match the signature of the original callback: (self, type, value)
            self.setProgressCallBack(self.__onProgress)
    
        def __onProgress(self, prog_type, value):
            """Progress monitoring"""
    
            # One example "progress type" is the "PAGE" key. Which indicates
            # which page reportlab is working on.
            if prog_type == "PAGE":
                print "Drawing page: %s" % value
            elif prog_type == "FINISHED":
                print "Drawing complete!"
    

    Here are some more values (you can see the code in reportlab.platypus.doctemplate):

    def progressCB(typ, value):
        """Example prototype for progress monitoring.
    
        This aims to provide info about what is going on
        during a big job.  It should enable, for example, a reasonably
        smooth progress bar to be drawn.  We design the argument
        signature to be predictable and conducive to programming in
        other (type safe) languages.  If set, this will be called
        repeatedly with pairs of values.  The first is a string
        indicating the type of call; the second is a numeric value.
    
        typ 'STARTING', value = 0
        typ 'SIZE_EST', value = numeric estimate of job size
        typ 'PASS', value = number of this rendering pass
        typ 'PROGRESS', value = number between 0 and SIZE_EST
        typ 'PAGE', value = page number of page
        type 'FINISHED', value = 0
    
        The sequence is
            STARTING - always called once
            SIZE_EST - always called once
            PROGRESS - called often
            PAGE - called often when page is emitted
            FINISHED - called when really, really finished
    
        some juggling is needed to accurately estimate numbers of
        pages in pageDrawing mode.
    
        NOTE: the SIZE_EST is a guess.  It is possible that the
        PROGRESS value may slightly exceed it, or may even step
        back a little on rare occasions.  The only way to be
        really accurate would be to do two passes, and I don't
        want to take that performance hit.
        """
        print 'PROGRESS MONITOR:  %-10s   %d' % (typ, value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python file that will not correctly perform an import. If I
For some reason, Xcode will not take input from a file, while Visual C++
I'm using GAE[JAVA] to do some image processing. GAE will not allow write file
with-open-file will read from the beginning of a file. If the file is VERY
In my app I download a file from amazon's s3, which does not work
I am trying to create a GUI to display information read from a file.
I have designed a database whose MDF file will be copied to remote offices,
I am writing data in a file. The file will look like this. [section1]
config.php put at the root level, this file will be included in any pages.
I have created a voice recorder applet. The output sound file will be .wav

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.