Skip to Content
เมนู
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3762 มุมมอง

Hi developers 

please can help me to solve my issue   
for example 

I have pdf file with size 1MB , I compressed file by tools get 200K after that i upload as binary 

Can do that direct by odoo code or python ?

Thanks 

อวตาร
ละทิ้ง

Is this issue is resolved?

คำตอบที่ดีที่สุด

Hi,

Here's a simple example of how you can integrate PDF compression with a button-click action in an Odoo model:


from odoo import models, fields, api

import PyPDF2


class MyModel(models.Model):

    _name = 'my.model'


    name = fields.Char(string="Name")

    pdf_file = fields.Binary(string="PDF File")


    @api.multi

    def compress_pdf(self):

        for record in self:

            input_pdf = PyPDF2.PdfFileReader(io.BytesIO(base64.b64decode(record.pdf_file)))

            output_pdf = PyPDF2.PdfFileWriter()


            for page_num in range(input_pdf.numPages):

                page = input_pdf.getPage(page_num)

                output_pdf.addPage(page)


            output_stream = io.BytesIO()

            output_pdf.compressContentStreams()

            output_pdf.write(output_stream)


            record.pdf_file = base64.b64encode(output_stream.getvalue())


            output_stream.close()


Make sure to adjust the code according to your specific requirements and the structure of your Odoo module. Additionally, don't forget to handle error cases and edge scenarios appropriately.


Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Can you describe in details your case

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
พ.ย. 23
1071
4
ก.ค. 23
4535
what is the name of this app แก้ไขแล้ว
1
ธ.ค. 21
1951
0
พ.ค. 20
2061
Is Odoo Documents (DMS) avaliable in CE? แก้ไขแล้ว
1
ม.ค. 20
2617