2016-12-01 8 views
1

私は.png画像のリストを持っています。私はそれらのすべてを1ページに9枚の画像を1つのpdfに変換する必要がありますが、垂直に並べて配置するのではなく、すべての幅を埋め、次の行まで続けます。写真の 額は、毎回異なることができます(12、... 15)pythonの1つのpdfに画像を変換

私は

from fpdf import FPDF 

list_of_images = [1.png, 2.png, ... 15.png] 
w = 70 
h = 60 
pdf = FPDF(orientation = 'L') 
for image in list_of_images: 
    pdf.image(image, w=sizew, h=sizeh) 
pdf.output("Memory_usage.pdf", "F") 

とも

template = Template('''<!doctype html> 
<html> 
<body> 
     <div style="display: flex; flex-direction: row"> 
     {% for image in images %} 
      <img src="{{ image }}" /> 
     {% endfor %} 
     </div> 
</body> 
</html>''') 
list_of_images = [1.png, 2.png, ... 15.png] 
html = template.render(images=list_of_pict) 
with open("my_new_file.html", "wb") as fh: 
    fh.write(html) 

p = subprocess.Popen(['wkhtmltopdf', '-', 'Memory_usage.pdf'], stdin=subprocess.PIPE, universal_newlines=True) 
p.communicate(html) 
p.wait() 

をwkhtmltopdfが、それらの両方は、各画像1を配置FPDFを試してみました

答えて

0

FPDFを使用して各画像を必要な座標に配置するだけです。

pdf.image(image, x=50, y=100, w=sizew, h=sizeh) 

FPDFドキュメントの詳細:image

関連する問題