+1 vote
35 views

In custom module for Odoo 12 CE I've extended sale.order.line class and added the function, which merges separate .png images in one .pdf file. For this task I use library Pillow 6.0.0.

image_files = [<PIL.Image.Image image mode=RGB size=800x1400 at 0x118295908>, <PIL.Image.Image image mode=RGB size=800x1400 at 0x118295B38>]
filename = "test.pdf"
image_files[0].save(filename, "PDF", resolution=100.0, save_all=True, append_images=image_files[1:])

I added this method to the button in order_line_form, but when I click into it I got error message:

 File ".../models/sale_order_line.py", line 261, in generateLabel
    image_files[0].save(filename, "PDF", resolution=100.0, save_all=True, append_images=image_files[1:])
  File "/...virt/lib/python3.7/site-packages/PIL/Image.py", line 1994, in save
    save_handler = SAVE_ALL[format.upper()]
KeyError: 'PDF'

Troubleshooting: I've created test .py project outside of Odoo where I tested this function by using the same virtual environment with the same packages and it works as expected: all png files are merged in one pdf file.

why it doesn't work when I run it from Odoo module?

in Back-end by (10.5k points) | 35 views

1 Answer

0 votes

try to use the FPDF which should convert to the png to pdf.

import os from odoo.tools 
import pdf from fpdf
import FPDF
import base64 from odoo import models, fields, api, _
from odoo.exceptions import Warning, ValidationError

 

by (8.8k points)
202 questions
178 answers
34 comments
112,142 users