21 Jan Odoo PDF attachment Compression
Odoo PDF Attachment Compression
1- Compress pdf based on a set of rules
2Flexible rules for compression:
- By model where pdf are uploaded.
-By ratio; allows to compress images inside pdf to configured ratio.
-By minimum image width; allows to compress images inside pdf which width bigger than configured width.
-By quality; allows to compress images inside pdf to configured quality.
-By size; it allows to compress images having a bigger size than the configured size.
![icon Odoo PDF Attachment](https://azka.tech/wp-content/uploads/2022/01/icon.png)
Checkout below step-by-step guide:
Configuration
- Configuration: Setup a compression rule
- Select the modules where pdf attachments to be compressed
![Model](https://azka.tech/wp-content/uploads/2022/01/model-1024x238.png)
- Set the compression ratio
![reduction rate](https://azka.tech/wp-content/uploads/2022/01/ratio-1024x302.png)
- Set the optional minimum image width inside pdf attachment
![min image width](https://azka.tech/wp-content/uploads/2022/01/min_img_width-1024x264.png)
- Set the optional minimum size of the image
![min size](https://azka.tech/wp-content/uploads/2022/01/min_size-1024x238.png)
- Set the optional newer than/older than days to compress.
![Newer than/older than](https://azka.tech/wp-content/uploads/2022/01/newer-1024x293.png)
- Set the quality of the compressed image (value between 0 and 100 where the larger the value, the higher the compression but the lower the quality).
![Quality](https://azka.tech/wp-content/uploads/2022/01/quality-1024x313.png)
- In Odoo, storage is done by content. Thus, if the same pdf was uploaded twice, it will be saved on the disk once.
- Thus, there is an option to match all similar pdf, compress them and delete the uncompressed pdf.
- To activate this feature, check the “Replace All”
- If you want the scheduled action to run this compression rule daily, keep it active.
Scheduled Action
- Upon installing the module, a daily scheduled action “Run attachments compression rules” is added automatically
![Action](https://azka.tech/wp-content/uploads/2022/01/action-1024x412.png)
How it works
- Add pdf: Add some pdf attachments that contains images in the models.
In the following example, we selected the sale model in my compression rule. So, we are adding 2 pdf files which contain images.
![pdf compress](https://azka.tech/wp-content/uploads/2022/01/pdf_before-1024x584.png)
- Run the compression rule: Go to the corresponding compression rule and run it. The pdfs satisfying these rules should be compressed.
The system will show a pop up with the details of the compression:
compressed pdf and total size reduction
![Compress](https://azka.tech/wp-content/uploads/2022/01/comp-1024x377.jpg)
- Check the results: Go back to the model where the pdf was uploaded and verify the results.
Download the pdf and check the size reduction.
![PDF after compression](https://azka.tech/wp-content/uploads/2022/01/pdf_after-1024x516.png)
- File Store: Notice that upon running a compression rule or when the scheduled action runs them,
the size of the file store is reduced if Replace All was checked