ReportLabs is a great tool, but you have to watch your permissions.

I would put a sample bit of code into createPdf.py, and try running it
firstly as root
to confirm the createPdf.py works, and then as your apache user;

su -u www-data python createPdf.py

I would suspect that the line c.save() throws an error due to write
permissions.

Another thing you may look at - you can pass anything that looks like
a file into Canvas.
I use a fileobject which i leave up to the python temp file code to
handle.
Once i have my temporary file, i pass that to Canvas like this;
myCanvas = canvas.Canvas(self.fileobject, pagesize=self.pagesize)
(self.pagesize is set somewhere else)

then i do all my drawing, and then save and rewind the file ;
myCanvas.save()
self.fileobject.seek(0)

then i can do this (django-specific code here);

response = HttpResponse(label.fileobject.read(),
                                                        mimetype =
'application/x-pdf')



Regards,

MrKiwi

On Oct 6, 8:28 pm, nitin chandra <[email protected]> wrote:
> Hi  All,
>
> I am looking to generate a PDF page from the data submitted in a web form.
>
> For this I am using REportLab.
>
> from reportlab.lib.pagesizes import letter
> from reportlab.pdfgen import canvas
>
> class Handler:
>      def do(self, environ, start_response):
>          form = cgi.FieldStorage(fp=environ['wsgi.input'],
>                                  environ=environ)
>
>          html = """
>                   <meta http-equiv="refresh"
> content="0;url=https://www.mywebsite.in/home.py"; /> """
>
>          printpdf = form.getvalue('print') ## This is a checkbox in
> html { If checked then create the PDF file}
>          if printpdf == 1:
>                c = canvas.Canvas('Patient_info.pdf', pagesize=letter)
>                c.setFont('Helvetica', 12)
>                c.drawString(30,750, ptbn)
>                c.showPage()
>                c.save()
>                os.open("open Patient_info.pdf")
>
>          output = html
>          mimeType = "text/html"
>
>          status = "200 OK"
>          response_headers = [("Content-type", mimeType),
>                             ("Content-length", str(len(output)))]
>
>          start_response(status, response_headers)
>          return [output]
>
> If i enter the code in python prompt, from c = canvas .... , a PDF
> file is created and saved in the current working directory.
>
> But not when I am doing it from a webpage.py file. There is no error,
> the PDF web page / Acroread does not open / launch the page.
>
> Do I need to add / change some thing, if wsgi requires it, in the
> above code to generate the PDF file ? If yes, then how should the line
> be written?
>
> Thank you
>
> Nitin

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to