I tried subclassing it this way.. The purpose here is to just get it
working for JPEG

class MyImageReader(ImageReader):
   def __init__(self, filep):
        if isinstance(filep,ImageReader):
            self.__dict__ = fileName.__dict__   #borgize
            return
        #the relevant engine.
        self.fileName = "Noname"
        self.format = 'JPEG'
        self._image = filep
        self._width = None
        self._height = None
        self._transparent = None
        self._data = filep
        self._dataA=None
        #if _isPILImage(fileName):
        self.fp = filep
        from reportlab.pdfbase.pdfutils import readJPEGInfo
        self._width,self._height,c=readJPEGInfo(self.fp)
        self.jpeg_fh = self._jpeg_fh
        self.fp.seek(0)

class PdfHandler(webapp.RequestHandler):

  def get(self):
    self.response.headers['Content-Type'] = 'application/pdf'
    self.response.headers['Content-Disposition'] =
'filename=somefilename.pdf'
    p = canvas.Canvas(self.response.out, pagesize=A4)
      .
      .
      .
    graphtoembed = urlfetch.fetch("http://somedomain.ext/images/
test.jpg")
    img_fp = StringIO(graphtoembed.content)
    img_obj = MyImageReader(img_fp)
    p.drawInlineImage(img_obj, 200,800)
    p.showPage()
    p.save()


And this results in
.
.
 File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py",
line 566, in format
    s.decode('pdfdoc')
  File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/
rl_codecs.py", line 1022, in _rl_codecs
ImportError: No module named pdfmetrics

I have no clue whats happening here... In ususal way of reportlab
(where file is loaded from filesystem , passing just filename to
drawImage) I was never asked for pdfmetrics lib.

Any help....





On Jan 12, 8:08 pm, djidjadji <djidja...@gmail.com> wrote:
> Why don't you subclass ImageReader.
> This class contains the image Blob and serves it like an ImageReader.
> Just implement the ImageReader methods needed for drawing.
>
> 2009/1/11 NewPyHacker <abhishek.parol...@gmail.com>:
>
>
>
> > Hi,
> >  I spent a lot of time trying to figure out ways to embed images in
> > pdf , I tried all sorts of stuff and hacks but stuck at this problem.
>
> > 1.) I want to embed a google chart
> >http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl...World
> >  2.) hence I do: graphtoembed = urlfetch.fetch("http://
> > chart.apis.google.com/blah....blah")
> > 3.) problem is, Reportlab's drawImage requires a file name to embed
> > this image or can take ImageReader object (which in turn asks for
> > localfile name in constructor)
> > 4.) How should I pass image content read from urlfetch to reportlab
> > while I am not allowed to dynamically create/store files in app
> > engine?
>
> > Even just for a test if I do this for static images,
> >    path = os.path.join(os.path.dirname(__file__), 'static/images/
> > test.gif')
> >    img_obj = ImageReader(path)
> >    canvas.drawImage(img_obj, 200,800)
>
> > I get this
> >  Cannot open resource "/base/data/home/apps/onepageresume
> > [blah....blah]"
>
> > Please show me direction... The goal is simple , just to retrieve
> > images from google charts and embed in a pdf...


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to