Displaying a pdf file.
Hello, What is the best way to display a pdf file in a zope application. I may select the file from an oracle database of get it from a file system. I'm not sure at the moment. My Zope Bible book shows how to upload a pdf file from a filesytem then view it. But in my case the pdf I want to view is based on an ID entered by the user. There may be many different pdf and I can't upload them all. I want to be able to 1) if the the pdf is on server then view (\docs\my.pdf) using the correct application type or 2) if I select the pdf from an oracle table (stored as a BLOB) <dtml-in sql-get_pdf> somehow display the pdf </dtml-in> Thanks for your help Mike Guerrero
Michael, Could you be more specific? What is it *exactly* you cannot do? Your question raises alot of issues. if you just want to know what do once you have access to the correct pdf then do something like (roughly in code) *yourExternalPythonScript* def someName(self,REQUEST,RESPONSE): parent = self.aq_parent res = parent.yourZsql(pdf_id = REQUEST[pdf_id]) # get the pdf from your DB record = res.dictionaries() for n in record: pdf = record['PDF'] RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader('Content-Length',len( pdf )) RESPONSE.write( pdf) *the calling dtml script that displays the pdf* <dtml-call "REQUEST.set('pdf_id',pdf_id)"> <dtml-call "yourExternalPythonSCript(PARENTS[0],REQUEST,RESPONSE)"> David ----- Original Message ----- From: Michael Guerrero To: zope@zope.org Sent: Thursday, August 14, 2003 4:38 PM Subject: [Zope] Displaying a pdf file. Hello, What is the best way to display a pdf file in a zope application. I may select the file from an oracle database of get it from a file system. I'm not sure at the moment. My Zope Bible book shows how to upload a pdf file from a filesytem then view it. But in my case the pdf I want to view is based on an ID entered by the user. There may be many different pdf and I can't upload them all. I want to be able to 1) if the the pdf is on server then view (\docs\my.pdf) using the correct application type or 2) if I select the pdf from an oracle table (stored as a BLOB) <dtml-in sql-get_pdf> somehow display the pdf </dtml-in> Thanks for your help Mike Guerrero ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Just a word of caution -- MS IE does not respect the Content-Type mime header. The file *must* have a '.pdf' extension. On Thu, 14 Aug 2003, David Hassalevris wrote:
Michael,
Could you be more specific? What is it *exactly* you cannot do? Your question raises alot of issues.
if you just want to know what do once you have access to the correct pdf then do something like (roughly in code)
*yourExternalPythonScript* def someName(self,REQUEST,RESPONSE): parent = self.aq_parent res = parent.yourZsql(pdf_id = REQUEST[pdf_id]) # get the pdf from your DB record = res.dictionaries() for n in record: pdf = record['PDF']
RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader('Content-Length',len( pdf )) RESPONSE.write( pdf)
*the calling dtml script that displays the pdf* <dtml-call "REQUEST.set('pdf_id',pdf_id)"> <dtml-call "yourExternalPythonSCript(PARENTS[0],REQUEST,RESPONSE)">
David ----- Original Message ----- From: Michael Guerrero To: zope@zope.org Sent: Thursday, August 14, 2003 4:38 PM Subject: [Zope] Displaying a pdf file.
Hello,
What is the best way to display a pdf file in a zope application. I may select the file from an oracle database of get it from a file system. I'm not sure at the moment.
My Zope Bible book shows how to upload a pdf file from a filesytem then view it. But in my case the pdf I want to view is based on an ID entered by the user. There may be many different pdf and I can't upload them all.
I want to be able to 1) if the the pdf is on server then view (\docs\my.pdf) using the correct application type
or 2) if I select the pdf from an oracle table (stored as a BLOB) <dtml-in sql-get_pdf> somehow display the pdf </dtml-in>
Thanks for your help
Mike Guerrero
------------------------------------------------------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hi Michael, Michael Guerrero wrote:
Hello,
What is the best way to display a pdf file in a zope application. I may select the file from an oracle database of get it from a file system. I'm not sure at the moment.
My Zope Bible book shows how to upload a pdf file from a filesytem then view it. But in my case the pdf I want to view is based on an ID entered by the user. There may be many different pdf and I can't upload them all.
Normally you do it neither way. See the file library exaple in your /Examples folder in Zope how to do such a beast. Regards Tino Wildenhain
What is the best way to display a pdf file in a zope application. I may select the file from an oracle database of get it from a file system. I'm not sure at the moment.
My Zope Bible book shows how to upload a pdf file from a filesytem then view it. But in my case the pdf I want to view is based on an ID entered by the user. There may be many different pdf and I can't upload them all.
I want to be able to 1) if the the pdf is on server then view (\docs\my.pdf) using the correct application type
or 2) if I select the pdf from an oracle table (stored as a BLOB) <dtml-in sql-get_pdf> somehow display the pdf </dtml-in>
You could write a script to automatically upload everything to Zope, use load_site.py, or copy your files using FTP or WebDAV. If you really want to get them from the FS, get LocalFS and make a LocalFS object that points to, say, /docs. That's probably the easiest way. Well, aside from FTP. If you want to grab it from a table, you'll want to write a Python script (with a .pdf extension!) that returns a single BLOB field, gotten by way of a ZSQL method. How that field is selected from the table can be determined by REQUEST variable parameters, acquisition context, or several other means. Obviously, this takes more work. Just remember that you *cannot* display the data inline. That will never work: you must return it looking like a single file. --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (5)
-
David Hassalevris -
Dennis Allison -
J Cameron Cooper -
Michael Guerrero -
Tino Wildenhain