Edinburgh-Genome-Foundry / blabel

:label: Python label/sticker PDF generation. HTML templates, built-in barcodes, qr codes, and other goodies
https://edinburgh-genome-foundry.github.io/blabel
MIT License
178 stars 37 forks source link

Python Blabel generate broken PDF file #10

Open dsztandarski opened 3 years ago

dsztandarski commented 3 years ago

I am writing a program to handle label printing on a thermal transfer printer. I have a problem with corrupted PDF files after generating them with blabel. For example, if I generate a label with the serial number VWAB123456, everything is fine, but in the case of the serial number VWAC123456 a corrupt PDF file is generated.

Damaged PDF after printing with Sumatra PDF looks fine, but bold font disappears and the font type changes. It looks like CSS is not being used at all at the moment. Adobe Reader error below: Broken PDF Damagen PDF Image

Label without bold (broken PDF file) Label without bold

Label with bold (fine PDF) Label with bold

Python code: Python code

HTML code: HTML code

CSS sheet: CSS sheet

Can anyone help me with this problem?

veghp commented 3 years ago

Thanks for posting a detailed example. Your code works fine here on Ubuntu, without running the lines with sumatra. A couple of comments on what may cause this issue: from what you wrote, blabel correctly made at least one PDF, so the package seems to work fine. You are sourcing the logo over the net, and that can be a problem (repeated access / delay / etc). Try using a local image. If the label is wider or longer than the page, as is in your example, then part of it will not be printed on the page. Perhaps that can be a problem and interpreted as corrupted file? If you are running your code as posted, sumatra may try to access the pdf at the same time as the python code (or the next iteration if you are running as a loop). Try using a different filename for each pdf. Finally, this package was developed on Ubuntu (GNU/Linux) and not Windows (but as mentioned above, it would cause an error in all files).

dsztandarski commented 3 years ago

I checked your suggestions and unfortunately the program that runs on Windows continues to generate corrupted PDF files. I installed Ubuntu in Virtualbox and ran the program on Ubuntu 20.04 LTS and in this case the program works fine and generates correct PDF files.

Is there any way to fix this problem for a program that runs on Windows 10?

Zulko commented 3 years ago

This library uses weasyprint to generate the PDFs, it might be worth checking with them if they are aware of Windows issues.

Another possibility is that the font used (on Windows) is causing the problem.

dsztandarski commented 3 years ago

I found a solution. The problem was caused by the cairo library version 1.17.4, I installed the older version of GTK3-Runtime (including cairo version 1.16.2) from 2019-11-07 from the link below and the files are generated correctly :)

https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases/tag/2019-11-07

veghp commented 3 years ago

That's great to hear, thanks for sharing