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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:40:15+00:00 2026-06-09T05:40:15+00:00

Using pdftk I generate some dynamic temporary pdf files, which then Django serves to

  • 0

Using pdftk I generate some dynamic temporary pdf files, which then Django serves to the user.

On a desktop, it works fine – the pdf file opens which then user can save, however on my android phone in all browsers (maybe the same on iOS but don’t have and iOS device so can’t test), the pdf does not download successfully. It starts the download but then always fails and I can’t figure out why.

The following is a snippet of the view and the function which generates the pdf binary data:

def get_pdf():
    fdf = {...}
    t1 = tempfile.NamedTemporaryFile(delete=False)
    t2 = tempfile.NamedTemporaryFile(delete=False)
    t1.file.write(fdf)

    # close temp files for pdftk to work properly
    t1.close()
    t2.close()

    p = Popen('pdftk %s fill_form %s output %s flatten' %
              ('original.pdf', t1.name, t2.name), shell=True)
    p.wait()

    with open(t2.name, 'rb') as fid:
        data = fid.read()

    # delete t1 and t2 since they are temp files

    # at this point the data is the binary of the pdf
    return data


def get_pdf(request):
    pdf = get_pdf()

    response = HttpResponse(pdf, mimetype='application/pdf')
    response['Content-Disposition'] = 'filename=foofile.pdf'
    return response

Any ideas as to why this might be happening?

  • 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-09T05:40:16+00:00Added an answer on June 9, 2026 at 5:40 am

    As per @Pascal comment, I added Content-Length and the downloads now work on mobile devices.

    However it was not being downloaded with the filename I assign it in the view. Adding attachment fixes this but I don’t want the attachment to be present for desktop browsers. Hence the following is my final solution which works.

    # I am using the decorator from http://code.google.com/p/minidetector/
    @detect_mobile
    def event_pdf(request, event_id, variant_id):
        pdf = get_pdf()
    
        response = HttpResponse(pdf, mimetype='application/pdf')
        response['Content-Disposition'] = '%sfilename=foofile.pdf' %
            request.mobile and 'attachment; ' or ''
        response['Content-Length'] = len(pdf)
        return response
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using pdftk for flattening PDF files on server. For this purpose I use
I'm using pdftk and doing some testing and finding that bursting a multipage PDF
I'm using pdftk to concatenate pdf files on the fly by making an exec()
I am using Dompdf to generate A5 pdf documents from a html template and
I'm using php with PDFTK on Ubuntu. When filling a PDF with data, I
I'm coding a Python script which is using the application pdftk a few times
I use pdftk to compress a pdf using the following command line pdftk file1.pdf
I'm using pdftk to fill in a PDF form with an XFDF file. However,
I have a function to compress my pdf file using pdftk: (defun compresspdf (filename)
Using powershell I need to loop a series of pdf file and make some

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.