The ScaleTo parameter behaviour in the NReco.PdfRenderer.PdfToImageConverter in Windows

143 Views Asked by At

I'm trying to render a scaled image using the code:

new PdfToImageConverter
{
    ScaleTo = 2200
}
.GenerateImage(
    "sample.pdf",
    1,
    ImageFormat.Png,
    "sample.pdf.png");

The code renders a good proportional image under Ubuntu, but a squared image under Windows.

The squared window has a white field:

enter image description here

Sample application: https://github.com/sergei-voronkov/Test.NReco.ScaleTo

Also, the generated image is correct if I try to generate it using native poppler utility pdftoppm.exe under Windows:

pdftoppm.exe -png -aa yes -aaVector yes  -f 1 -l 1 -singlefile  -scale-to 2200 sample.pdf sample.pdf

The command line generates a proportional scaled image:

enter image description here

2

There are 2 best solutions below

0
Sergey Voronkov On BEST ANSWER

The problem has been fixed in the version 1.5.0.

2
Vitaliy Fedorchenko On

The behaviour is different because 'pdftoppm' versions are different.

On Windows, NReco.PdfRenderer uses poppler tools binaries that are shipped in the nuget package -- they are extracted on first use and there is no need to deploy them manually. The latest NReco.PdfRenderer includes poppler 21.03 release. In this version "-scale-to" parameter works differently, it always renders to square image; say, if ScaleTo=2000 then output always is 2000x2000. It seems this bug is already known and fixed: https://gitlab.freedesktop.org/poppler/poppler/-/issues/1062. I'll check that, maybe it would be enough to prepare a new NReco.PdfRenderer release with the latest poppler tools binaries for Windows. As a temporary workaround, you may consider to use "Dpi" property to get better resolution for your output images.

On Linux you may choose what poppler tools version to install, and I guess in your case this version is older (like 0.68 or earlier), where "-scale-to" works correctly.