2013-08-26 36 views
2

我有1000个PNG图像,并使用ReportLab的到 这些图像添加到PDF, 代码:如何添加数千图像转换成PDF使用ReportLab的

高清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 

高清draw_sourcepic(self_dir,pic_list):

pic = [pic_list[i:i+3] for i in range(0,len(pic_list),3)] 
data = [] 
i = 0 
for val in pic: 
    eachline = [] 

    for 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) 

但其具有以下错误: IO错误:无法打开资源“C:\ workspace \ decode \ 2012 \ result \ pic \ 510.png 这可能意味着我打开了太多图片,

官方文档说: 图片(数码图片)。支持PIL/Java 1.4(Python/Java影像库)的格式。目前,流动图像总是以帧为中心的 。我们允许两种懒惰方式允许文档中的许多图像 。可能会导致文件句柄饥饿 懒=所需然后关闭它,当1不打开图像,直到需要 懒= 2打开的图像

但是,当我改变了这个:。 targetimg =像(PIC_PATH,TX ,ty,lazy = 2) 它有以下错误: AttributeError:._file

如何添加数以千计的图像es转换成PDF?问题很长,

回答

0

我知道这是晚了一年,但我最近遇到了类似的问题。我认为这是reportlab的一个问题 - 当lazy = 2时,图像在其需要的文件属性被销毁后再次被调用。我已经报告了问题和我的解决方法here。希望能帮助到你。