代码整合
from PIL import Image
import os
class do_it(object):
def __init__(self):
self.download="./pdf/"
# 保存目录
def create_img_pdf(self,file_name,ouput_pdf):
page = Image.new('RGB', (2480, 3508), 'white')
image=Image.open(file_name)
i_w,i_h=image.size
if i_w>i_h:
i_n_w=2000
i_n_h=int(i_h*2000/i_w)
else:
i_n_h=3000
i_n_w=int(i_w*3000/i_h)
n_img=image.resize((i_n_w,i_n_h))
page.paste(n_img,(100,100))
page.save(ouput_pdf,"PDF", resolution=100.0)
def topdf(self,nfile):
#保存在当前的pdf文件夹
# nfile必须独一无二
com="libreoffice --convert-to pdf:writer_pdf_Export "+nfile+" --outdir "+self.download
os.system(com)
name=nfile[nfile.rfind('/')+1:nfile.rfind('.')]+".pdf"
newa=self.download+name
return newa
def combine(self,file_list,out_file):
file_info=""
for i in file_list:
file_info=file_info+" "+i
com="pdftk "+file_info+" cat output "+out_file
os.system(com)