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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:14:18+00:00 2026-05-30T18:14:18+00:00

I have a method that generates a PDF file using Reportlab library: def obtenerPDFNuevoPedido(self,

  • 0

I have a method that generates a PDF file using Reportlab library:

def obtenerPDFNuevoPedido(self, handler,rsUsuarioPedido, rsPedido):
    handler.response.headers['Content-Type'] = 'application/pdf'
    handler.response.headers['Content-Disposition'] = 'attachment; filename=output.pdf'
    story = []
    story.append(Paragraph('CHIPAS', ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=20)))
    story.append(Paragraph('____________ENLANUBE', ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=20)))
    story.append(Spacer(6, 22))
    story.append(Table([[Paragraph(str(strftime("%Y-%m-%d", gmtime())), ParagraphStyle(name="centeredStyle", alignment=TA_LEFT, fontSize=7)), 
    Paragraph(str(strftime("%H:%M:%S", gmtime())), ParagraphStyle(name="centeredStyle", alignment=TA_RIGHT, fontSize=7))]],colWidths=[5.05 * cm, 3.1 * cm]))
    story.append(Paragraph("DEVELOPED AT ROSHKA-LABS", ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=6)))
    story.append(Paragraph('-'*50, styleCentered))
    #...
    #...
    doc = SimpleDocTemplate(handler.response.out, pagesize=letter)
    doc.build(story) 

when I call that method, it opens a save dialog, where I can specify where the file should be saved.

How should I do to attach the generated pdf in email?

I have seen this example:

from google.appengine.api import urlfetch
from google.appengine.api import mail  

url = "http://www.abc.com/files/file.pdf" 
result = urlfetch.fetch(url)

if result.status_code == 200: 
  document = result.content

mail.send_mail(sender="youremail@yourdomain.com",
               to="receiver@hisdomain.com",
               subject="The file you wanted",
               body="Here is the file you wanted",
               attachments=[("The file name.pdf", document)])

But I don’t know how to apply it in this particular case.

Thanks in advance!

SOLUTION:

Based on the suggestion given by @Jesús, this is how I solved the problem:

class PdfTable(db.Model):
    fecha = db.DateTimeProperty(auto_now_add=True)
    archivoBlob = db.BlobProperty()

def obtenerPDFNuevoPedido(self, handler,rsUsuarioPedido, rsPedido):
#1)I generated the PDF this way:
        styleCentered = ParagraphStyle(name="centeredStyle", alignment=TA_CENTER)
        styleCenteredLeft = ParagraphStyle(name="centeredStyle", alignment=TA_LEFT)
        styleCenteredRight = ParagraphStyle(name="centeredStyle", alignment=TA_RIGHT)

        story = []
        story.append(Paragraph('CHIPAS', ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=20)))
        story.append(Paragraph('____________ENLANUBE', ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=20)))
        story.append(Spacer(6, 22))
        story.append(Table([[Paragraph(str(strftime("%Y-%m-%d", gmtime())), ParagraphStyle(name="centeredStyle", alignment=TA_LEFT, fontSize=7)), Paragraph(str(strftime("%H:%M:%S", gmtime())), ParagraphStyle(name="centeredStyle", alignment=TA_RIGHT, fontSize=7))]],colWidths=[5.05 * cm, 3.1 * cm]))
        story.append(Paragraph("DEVELOPED AT ROSHKA-LABS", ParagraphStyle(name="centeredStyle", alignment=TA_CENTER, fontSize=6)))
        story.append(Paragraph('-'*50, styleCentered))
        data = [[Paragraph("Usuario",ParagraphStyle(name="centeredStyle", alignment=TA_LEFT, fontSize=7)), Paragraph("Producto/Precio/Cantidad",ParagraphStyle(name="centeredStyle", alignment=TA_LEFT, fontSize=7)),Paragraph("Total", ParagraphStyle(name="centeredStyle", alignment=TA_RIGHT, fontSize=7))]]
        #
        #
        #
#2)Inside the same method, I saved the PDF file in the Datastore       
        pdf = StringIO.StringIO()

        doc = SimpleDocTemplate(pdf, pagesize=letter)
        doc.build(story)

        content = pdf.getvalue()

        blob = model.PdfTable()
        blob.archivoBlob = db.Blob(content)
        blob.put()
#3)The file recently stored  in the datastore was attached like this:        
        mail.send_mail(sender="youremail@yourdomain.com",
               to="receiver@hisdomain.com",
               subject="The file you wanted",
               body="Here is the file you wanted",
               attachments=[('resumen_pedido.pdf'), blob.archivoBlob)])

Although I don’t know if this is the more efficient way to solve the problem…but it works

  • 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-30T18:14:19+00:00Added an answer on May 30, 2026 at 6:14 pm

    I think the right way to do this is:

    • Generate the PDF file (first fragment of code)
    • Save the PDF file in the Datastore.
    • Use the second fragment of code to attach the PDF to the email.

    Try it and tell us =)

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

Sidebar

Related Questions

I have a method that returns a PDF file using DOMPDF . It sends
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
I have a class that generates PDF with Prawn: class CustomersReport < Prawn::Document def
Ok, so I have an action method that generates a PDF and returns it
I have a method that loads a Crystal Reports file, sets the appropriate login
So I have method that generates a barcode and label with that barcode. We
Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers
I have written an O/R database wrapper that generates some wrapper methods for stored
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to

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.