Hi, i'm working on a task that i want to convert text file into PDF one 
using conversion API that is in GAE , i tried as:
https://developers.google.com/appengine/docs/python/conversion/overview

This is the approach that i used:

from __future__ import with_statement
from google.appengine.api import files
import cgi, cgitb ; cgitb.enable()
import StringIO
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import mimetypes
from google.appengine.ext import blobstore
from mimetypes import guess_type
from google.appengine.api import conversion




def mime_type(filename):
    return guess_type(filename)[0]
class get(webapp.RequestHandler):
    def post(self):
        
        form = cgi.FieldStorage() 
        file_upload = form['file']  
        name=file_upload.filename  
         
        m=mimetypes.guess_type(name)[0]
        
        data=file_upload.file.read()
        buf = StringIO.StringIO()
        asset = conversion.Asset("text/plain", data, file_upload.filename)
        conversion_obj = conversion.ConversionRequest(asset, 
"application/pdf")
        result = conversion.convert(conversion_obj)
        if result.assets:
             buf.write(asset._data)
                
        else:
             print "ERROR" 
       
        
        u_file = 
files.blobstore.create(mime_type="application/pdf",_blobinfo_uploaded_filename="test.pdf")
        data=buf.getvalue()
        with files.open(u_file, 'a') as f:
                  f.write(data)
        files.finalize(u_file)
        blob_key = files.blobstore.get_blob_key(u_file)
          
       
        
  
def main():
    application = webapp.WSGIApplication( [(r'/get.py', get)], debug=True)
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

But when i try to open this PDF,i can't open it and the adobe reader gives 
error immediately that it can't open the file.
Sorry i'm still beginner in these issues,any help please?
Any suggestions are welcome. 
    
    

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/g2vssK1g2mcJ.
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/google-appengine?hl=en.

Reply via email to