2013-08-26 37 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。希望能幫助到你。