empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
492 stars 114 forks source link

The DrawImage Function Fails During Resizing #92

Open leesatoh opened 7 months ago

leesatoh commented 7 months ago

Hi, I'm attempting to create a PDF file containing a JPEG image. However, writing the image PERSONAL_IDENTIFICATION_1R-1.jpeg into the PDF does not work as expected. I aim to adjust the image size to fit A4 PDF dimensions, but the image in 'result.pdf' appears distorted and cut off.

I'm using .NET Framework 4.6.2 and PDFsharp 6.1.0-preview-1. Interestingly, when I switch to .NET Framework 4.6.2 and PDFsharp 1.51.5185-beta, the resizing functions correctly, and the image width adjusts as intended. SamplePdfSharpDrawImage.6.1.0-preview-1.zip

Could you please provide any insights or suggestions on how to resolve this issue? Your assistance would be greatly appreciated. Thank you in advance for your help and support.

ThomasHoevel commented 7 months ago

People who used PDFsharp 1.5 should try the GDI build of PDFsharp 6.1 to get the same functionality. That much can be said without trying your code.

ThomasHoevel commented 2 weeks ago

As far as I can tell, the image that causes this issue is corrupted: There is one file header that indicates that there is only one component (meaning grayscale image) while another file header indicates that there are three components (meaning RGB image).

So far, PDFsharp 6.x only used one header - the one that showed one component, leading to incorrect display with Adobe Reader. The current internal build now finds both headers - the one reporting three components is found first and will be used and the image displays correctly in Adobe Reader. This change could lead to problems with other corrupted JPEG images.

The change should be included with PDFsharp 6.2.0 Preview 2 (cannot give an ETA yet).