how to add thousands of image into a pdf with reportlab -


i have 1 thousand png images,and use reportlab add these images pdf, code is:

def pic_exits(pic_path):

if os.path.exists(pic_path):     #print ('pic_exits')     #print (pic_path)     target = pil.image.open(pic_path)                 #fp = open(pic_path,'rb')     #target = pil.image.open(fp)     #fp.close()             targetx,targety = target.size     del target     #print (targetx,targety)     tx,ty = get_xy(targetx,targety)     targetimg = image(pic_path, tx, ty) else:     targetimg = paragraph('<para align = center>not exist</para>',bodystyle)       return targetimg 

def draw_sourcepic(self_dir,pic_list):

pic = [pic_list[i:i+3] in range(0,len(pic_list),3)] data = [] = 0 val in pic:     eachline = []      pic_path in val:         i+=1         pic_image = pic_exits(pic_path)         eachline.append(pic_image)     while len(eachline) < 3:         eachline.append(none)     data.append(eachline)        pic_table = drawtable(data,(150,150,150),none) story.append(pic_table)  

but has below error: ioerror: cannot open resource "c:\workspace\decode\2012\result\pic\510.png maybe means hava opened many images,

the offical documents said that: image (digital picture). formats supported pil/java 1.4 (the python/java imaging library supported. @ present time images flowables centered horozontally in frame. allow 2 kinds of lazyness allow many images in document lead file handle starvation. lazy=1 don't open image until required. lazy=2 open image when required shut it.

but when changed this: targetimg = image(pic_path, tx, ty, lazy = 2) has following error: attributeerror: ._file

how can add thousands of images pdf? question long,

i know year late, encountered similar problem. think problem reportlab--when lazy=2, image called upon again after needed file attribute been destroyed. i've reported issue , workaround here. hope helps.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -