Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain PNG images are skewed when rendering in Core build of PDFsharp #168

Open
bsouthard-jackhenry opened this issue Sep 5, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@bsouthard-jackhenry
Copy link

Expected Behavior

I expect the PNG image to render correctly. The PNG in question seems to be valid and is viewable elsewhere (MS Paint, GIMP, Chrome, etc.).

Actual Behavior

The PNG file is rendered skewed. Please see the image below:
image

Steps to Reproduce the Behavior

Please see the example in the attached issue submission. A PNG file that demonstrates the issue is included.

Issue.zip

Thank you,
Brent Southard
[email protected]

@ThomasHoevel ThomasHoevel changed the title Certain PNG images are skewed when rendering in PDFsharp Certain PNG images are skewed when rendering in Core build of PDFsharp Sep 9, 2024
@ThomasHoevel
Copy link
Member

Both the GDI and WPF builds handle the image correctly.
I still have to investigate what goes wrong with the Core build.
As a workaround, the Core build handles the image correctly after conversion to BMP monochrome format and this has no impact on PDF file size.

@bsouthard-jackhenry
Copy link
Author

First, thanks for looking into this! I am new to PDFsharp and I have to say I'm very impressed with it.

We are specifically using the Core build to avoid GDI and WPF dependencies, unfortunately. May I ask what you used to convert the PNG to a monochrome BMP file? I tried to do that using Magick.NET and was unable to get monochrome output -- I ended up with an 8-bit image no matter what I tried. I'm limited by avoiding the System.Drawing namespace, otherwise I would have many viable options.

Brent

@ThomasHoevel
Copy link
Member

I used the good old Paint mspaint.exe. Select Monochrome under "Save as".
It is 1032 kB as BMP vs. 72 as PNG, but the BMP gets compressed in the PDF and final file size is the same.

@bsouthard-jackhenry
Copy link
Author

Ah, I'm in need of a programmatic solution. The full story is that our application deals with a wide variety of image formats and we need to convert any that are not of a PDFsharp-supported format (JPG, PNG, BMP for Core) to a supported format for inclusion in a generated PDF. The PNG in question was actually converted from a bitonal TIFF image using ImageGear.NET (we have an ImageGear license). At first I thought the blame here was with ImageGear's conversion, but the PNG seems valid and I can open it using a variety of applications. I will go back and try converting from TIFF to BMP using ImageGear and see if the BMP file generated that way is acceptable.

By the way, were you able to reproduce the skewing issue using the submitted code (using the Core library)?

Thanks again,
Brent

@ThomasHoevel
Copy link
Member

By the way, were you able to reproduce the skewing issue using the submitted code (using the Core library)?

Yes. Shame on me. My monochrome test images always had widths that are a multiple of 8.
2550 is not a multiple of 8 and needs adjustment at one point in code.

So the next preview of PDFsharp will handle this particular image correctly. Cannot yet give an ETA.

@ThomasHoevel ThomasHoevel added the bug Something isn't working label Sep 9, 2024
@bsouthard-jackhenry
Copy link
Author

That's great! I'm glad you've discovered the issue and I thought it was probably width related, based on the skewed output. I'm glad I could add a file to your image test library. :)

I think I might have a JPEG file that I had a different issue with. If I can find it I'll submit an issue for that as well. Not that I'm trying to be a troublemaker or anything...

Regards,
Brent

@ThomasHoevel
Copy link
Member

I just found out that the bug was not my original work, but already existed in the PNG library we use for the import. I feel a little bit better now.

JPEG files come in many different flavors and we added two more flavors in the past few months, but maybe there are more to come.

@bsouthard-jackhenry
Copy link
Author

@ThomasHoevel, will your fix still work despite the bug in the PNG library (BigGustave, it appears)?

@ThomasHoevel
Copy link
Member

PDFsharp includes an enhanced BigGustave library - now with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants