--- ECHO_content/ECHO_collection.py 2004/11/28 21:56:07 1.191 +++ ECHO_content/ECHO_collection.py 2004/11/29 20:39:08 1.192 @@ -9,7 +9,13 @@ class ECHO_externalLink contains informa """ +from reportlab.pdfgen import canvas +from reportlab.lib.pagesizes import A4 + + + import string +import tempfile import re import os import OFS.Image @@ -272,6 +278,7 @@ def manage_addECHO_fullText(self, id, ti REQUEST.RESPONSE.redirect(u+'/manage_main') return '' + class ECHO_resource(Folder,Persistent,ECHO_basis): """ECHO Ressource""" security=ClassSecurityInfo() @@ -283,6 +290,90 @@ class ECHO_resource(Folder,Persistent,EC security.declareProtected('View','index_html') + + + security.declareProtected('View','createPDF') + def createPDF(self,RESPONSE=None,local=None,dpi=150): + """erzeuge pdf file""" + pages=1 + + imagePath=self.getImagePath().replace("/mpiwg/online","") + + + image="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn="+imagePath+"&dw=%i&dh=%i&pn=%i" + xmlInfo="http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/dlInfo-xml.jsp?fn="+imagePath + dom=xml.dom.minidom.parse(urllib.urlopen(xmlInfo)) + for parameter in dom.getElementsByTagName('parameter'): + if parameter.getAttribute('name')=="pt": + pages=int(parameter.getAttribute('value')) + break + + tempfile.tempdir="/tmp/archivesImageServer" + + tmpPath=tempfile.mktemp() + + + tmpZip=tempfile.mktemp()+".pdf" + tmpFn=os.path.split(tmpZip)[1] + + + if not os.path.exists(tempfile.tempdir): + os.mkdir(tempfile.tempdir) + + if not os.path.exists(tmpPath): + os.mkdir(tmpPath) + + if RESPONSE: + RESPONSE.setHeader("Content-Type","text/html") + RESPONSE.write("

I am creating the pdf

") + txt="

1. step: getting the images( %i pages)

"%pages + RESPONSE.write(txt) + + c=canvas.Canvas(tmpZip) + for i in range(1,pages): + if RESPONSE: + RESPONSE.write(str("

Get Page: %i
\n"%i)) + faktor=dpi/72.0 + + fn=tmpPath+"/%i.png"%i + + width,height=A4 + #print image%(width*faktor,height*faktor,i) + url=urllib.urlopen(image%(width*faktor,height*faktor,i)).read() + fh=file(fn,"w") + fh.write(url) + fh.close() + + + + c.drawImage(fn,0,0,width=width,height=height) + c.showPage() + c.save() + if RESPONSE: + RESPONSE.write("

finished
\n") + + if RESPONSE: + len=os.stat(tmpZip)[6] + downloadUrl=self.absolute_url()+"/downloadPDF" + RESPONSE.write("""

Click here for download ( %i Byte)

\n"""%(tmpFn,len)) + RESPONSE.write("""

The file will be stored for a while, you can download it later, the URL is:

+

%s?fn=%s\n"""%(tmpFn,downloadUrl,tmpFn)) + RESPONSE.close() + + + def downloadPDF(self,fn): + """download prepared set""" + filename="/tmp/archivesImageServer/"+fn + namePDF=self.getId()+".pdf" + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename="%s" """%namePDF) + self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") + len=os.stat(filename)[6] + self.REQUEST.RESPONSE.setHeader("Content-Length",len) + images=file(filename).read() + self.REQUEST.RESPONSE.write(images) + self.REQUEST.RESPONSE.close() + + def getRDF(self,urn=None): """rdf""" ret=getRDFDescription(self,self.link,urn=urn) @@ -636,8 +727,11 @@ class ECHO_resource(Folder,Persistent,EC else: return "no fulltext available" - - def getImageView(self,noredirect=None): + def getImagePath(self): + """gibt pfad zum image aus""" + return self.getImageView(noredirect="yes",onlyPath="yes") + + def getImageView(self,noredirect=None,onlyPath=None): """getImages; give Imageviewr and if somthing goes wrong.""" try: fh=ECHO_helpers.urlopen(self.metalink) @@ -656,7 +750,10 @@ class ECHO_resource(Folder,Persistent,EC self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') self.REQUEST.RESPONSE.redirect(imageurl) else: - return imageurl + if not onlyPath: + return imageurl + else: + return archivepath+"/"+imagetemp except: if not noredirect: @@ -1190,7 +1287,7 @@ class ECHO_resource(Folder,Persistent,EC return getattr(self,item) def checkRDF(self,path): - """check if pdf behind path""" + """check if pdf in the path""" try: for fileName in os.listdir(path): if os.path.splitext(fileName)[1]==".pdf":