|
Hello, I am currently trying to create PDF files using TIF or
JPG files for my input. I have written a routine that creates the PDF file correctly using PIL to retrieve my
images. If I run the py2exe to create my exe file and run the program I get an error as follows ========================================== ERROR: test (__main__.CITLPDF) ------------------------------------------ Traceback (most recent call last): File "pdfgen.py", line 51, in test File "Image.pyc", line 1745, in open IOError: cannot identify image file ------------------------------------------ Ran 1 test in 0.000s FAILED (errors=1) I have added my pdfgen.py file for you to look at I have a folder in my Python24 folder named Instate To run my file from IDLE C:\Python24\Instate\pdfgen.py Create folders C:\Python24\Input C:\Python24\Output Create a text file in the input folder with “1”
entered as the text Name this file Pages.dat Copy a JPG file to the input folder and name it Page1.jpg The Pages.dat file is simply their to get the number of
pages The script reads this file then opens each page in turn and
adds The jpg to the PDF canvas Please can you tell me why this works in the IDLE but not in
runtime Thank You Gary Lehan Software
Development Manager (Microsoft
Sales Expert) Instate
Technology Ltd Tel : 0113
244 5150 www : http://www.instate.co.uk iTL |
#**************************************************** #* pdfgen.py * #* (c)Instate Technology Ltd 2005 * #* For Use Only With The iN-file Imaging System" * #* * #* Author : Gary Lehan * #* Date Created : 1/12/05 * #* Date Modified : 2/12/05 * #* * #* Usage: * #* To convert JPG/TIF images into PDF * #* * #* Export Tip: * #* BW Images - TIF Packbits compression * #* Color Images - JPG * #* Save both files as .GFD * #* * #****************************************************
import sys
import os
import string
import _imaging
import Image
from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses, outputfile
from reportlab.pdfgen.canvas import Canvas
inputpath = string.replace(sys.prefix + "\Input","\\","\\\\")
outputpath = string.replace(sys.prefix + "\Output","\\","\\\\")
pdfname = "INSTATE.PDF"
currentpage = 0
#Read the number of pages from the text file
fileHandle = open(inputpath + "\\pages.dat")
pagecount = fileHandle.read()
fileHandle.close()
class CITLPDF(unittest.TestCase):
def test(self):
c = Canvas(outputpath + "\\" + pdfname)
currentpage = 1
while currentpage <= string.atoi(pagecount):
fname = inputpath + "\\\\page" + str(currentpage) + ".jpg"
print fname
jpg = Image.open(str(fname))
#Draw our page on the PDF canvas
c.drawInlineImage(jpg,0,0,550,840)
#Commit Page 1 To Canvas And Setup For Page 2
c.showPage()
#Increment page counter
currentpage = currentpage + 1
#Save the file
c.save()
#Write a completion file
fileHandleComp = open(inputpath + "\\complete.py",'w')
fileHandleComp.write('Done')
fileHandleComp.close()
def makePDF():
return makeSuiteForClasses(CITLPDF)
#noruntests
if __name__ == "__main__":
unittest.TextTestRunner().run(makePDF())
_______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig
