[reportlab-users] Problem parsing file

Brandon Rich brich at caseta.com
Thu Jan 24 11:22:13 EST 2008



I have a file named violation that contains both paragraph and image
tags. While trying to pass these to a PDF, I can get the <para> to pass
and display properly but not the <image>. I think this is because the
tags themselves are being passed with the .jpg and as a result, I keep
getting an error. Can someone please give insight as to what they may
think the problem is, and any ideas how to get around it?

Thanks
B

file = open("violation.tmpl", "r")
tree = parse(file)
elem = tree.getroot()
for para in elem.findall('para'):
contents.append(Paragraph(ElementTree.tostring(para),
paragraphStyle, None))
for image in elem.findall('image'):
contents.append(Image(ElementTree.tostring(image)))

Traceback (most recent call last):
File "C:\workspace\pythonlibs\tests\document\pdfUtilTest.py", line 6,
in <module>
test_letter2(letters_file)
File "C:\workspace\pythonlibs\tests\document\pdfutil.py", line 117, in
test_letter2
pdfDoc.violationNotice(output_file)
File "C:\workspace\pythonlibs\tests\document\pdfutil.py", line 105, in
violationNotice
doc.build( contents, onFirstPage=self.firstPage,
onLaterPages=self.otherPages )
File
"C:\Python25\lib\site-packages\reportlab\platypus\doctemplate.py", line
911, in build
BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
File
"C:\Python25\lib\site-packages\reportlab\platypus\doctemplate.py", line
740, in build
self.handle_flowable(flowables)
File
"C:\Python25\lib\site-packages\reportlab\platypus\doctemplate.py", line
638, in handle_flowable
if frame.add(f, self.canv, trySplit=self.allowSplitting):
File "C:\Python25\lib\site-packages\reportlab\platypus\frames.py",
line 141, in _add
w, h = flowable.wrap(aW, h)
File "C:\Python25\lib\site-packages\reportlab\platypus\flowables.py",
line 373, in wrap
return (self.drawWidth, self.drawHeight)
File "C:\Python25\lib\site-packages\reportlab\platypus\flowables.py",
line 367, in __getattr__
self._setup_inner()
File "C:\Python25\lib\site-packages\reportlab\platypus\flowables.py",
line 346, in _setup_inner
img = self._img
File "C:\Python25\lib\site-packages\reportlab\platypus\flowables.py",
line 363, in __getattr__
self._img = ImageReader(self._file)
File "C:\Python25\lib\site-packages\reportlab\lib\utils.py", line 549,
in __init__
self.fp = open_for_read(fileName,'b')
File "C:\Python25\lib\site-packages\reportlab\lib\utils.py", line 445,
in open_for_read
raise IOError('Cannot open resource "%s"' % name)
IOError: Cannot open resource "<image>
C:\workspace\pythonlibs\tests\document\test_img.jpg
</image>

" fileName=<image>
C:\workspace\pythonlibs\tests\document\test_img.jpg
</image>


More information about the reportlab-users mailing list