pontedilana / php-weasyprint

PHP library allowing PDF generation or snapshot from an URL or an HTML page. Wrapper for Kozea/WeasyPrint
MIT License
52 stars 11 forks source link

php unit testing #8

Closed murraycollingwood closed 1 year ago

murraycollingwood commented 1 year ago

Hello

I'm trying to implement some php unit testing around my PDF generation. I can easily check the creation of the PDF document, but if I want to ensure it contains the text I'm looking for, formatted in a similar manner, I'm having trouble.

I found this article (https://stackoverflow.com/questions/32489513/software-testing-a-pdf-is-created-correctly) which suggested generating the PDF and comparing it to a previously generated PDF, which I tried, but it didn't work. Even though both contained exactly the same content the strings were never the same.

Do you have any suggestions how I might be able to ensure my PDF contains the correct content?

endelwar commented 1 year ago

Hi! Reproducible PDF as been introduced in WeasyPrint 55.0b1 and fixed in 56.0 (see https://github.com/Kozea/WeasyPrint/issues/1666).

in a comment to issue #1553 is suggested to add a meta tag to html:

<meta name="dcterms.created" content="2023-05-10">

Keeping the content fixed and setting a system ENV to a fixed value (SOURCE_DATE_EPOCH=0) should be enough to create reproducible pdf.

Let me know if this solves your problem!

endelwar commented 1 year ago

Was your problem solved with my suggestions?