pdf-visual-diff icon indicating copy to clipboard operation
pdf-visual-diff copied to clipboard

Regression on Windows after updating to 0.14.0

Open bakasmarius opened this issue 9 months ago • 2 comments

We use pdf-visual-diff to test the correctness of our PDF files that contain barcodes inside of them. After updating from 0.12.0 to 0.14.0 I was happy to finally get rid of canvas dependency but my snapshots started to fail in some unexpected ways (only in barcode parts).

Here is an example PDF file: barcodes.pdf - it has two pages with the same barcode in both of them. The only difference is the size of these pages - first page's height is several times smaller.

This is the PNG file generated with 0.12.0: barcodes_1x_v0 12 0

This is the PNG file generated with 0.14.0: barcodes_1x_v0 14 0

As you can see from the diff, the barcode in the first page has a lot of extra stripes while the same barcode in the second page has only one extra stripe: barcodes_1x diff

The biggest problem is that the one extra stripe in the second page is added only when I run the tests in Windows. In Linux that extra line is not generated, so now there is a discrepancy between Windows and Linux/Mac machines. If I update the snapshots on my Windows machine, the tests will fail on Linux pipelines because of that one extra line.

I accidentally found out about pdf2PngOptions so I managed to solve most of the discrepancies by multiplying the Dpi value by 4 ({ pdf2PngOptions: { dpi: Dpi.Low * 4 } }). For the rest of them, I had to change the text of the barcode value because it seems that not all the barcodes have this issue and not all of them can be fixed by scaling dpi. I'm lucky that our test data lets us change these values freely enough, but other developers might not be so lucky.

4x Dpi versions: This is the PNG file generated with 0.12.0: barcodes_4x_v0 12 0

This is the PNG file generated with 0.14.0: barcodes_4x_v0 14 0

As you can see, the second page does not have the extra stripe anymore: barcodes_4x diff

bakasmarius avatar Jan 15 '25 13:01 bakasmarius