-
Notifications
You must be signed in to change notification settings - Fork 132
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
DrawImage draws allways the same (first) image #127
Comments
Thanks for the feedback. Your code that does not work with the GDI build is this:
Here is a shorter version that works:
And here is an even shorter version that also works: Will investigate further next week. It should also work with the indirection to the MemoryStream object. There was a hyphen missing in the URL: |
Thanks for your fast response. But they both keep an file stream open, what i tried to avoid. i've added the following "File.Delete" at the end of the Main Routine
And the program throw the error In my productiv Application, i do not delete those files of course, but we have PDF outputs with a very large number of images included. So it would be very unhandy to keep them all open, during program execution. So i will look forward to your investigation next week, to enable MemoryStreams here again. |
…fore consumed streams are compared and wrongly treated as equal, which leads to all images in the document to be the same image.
I encountered the same problem in my production environment. Several customers have been severly affected with hundreds of wrongly printed qr codes. The culprit seems to be this dysfunctional code:
The md5 is always The work around for GDI with the check for the existence of When the memory stream is reset, everything works as expected.
So, I think the fix is, to check for the existence of |
The issue has been resolved with version 6.1.1 released today. |
Yes, the issue has been fixed with version 6.1.1 |
Hi, Update:- I hope this helps a little. |
Please use the Issue Submission Template so we can replicate your issue. |
Thank you for the fast reply. I would love to use the Submission Template. Only I have no idea what or where that is. Please forgive me. Sorry. I am using C# .NET Framework 4.8 in an MVC website. So again, sorry for my ignorance, is that GDI? I can say I am not developing a WPF project. Just a corporate website. Everything was going perfectly until I noticed this issue. I am in the process of creating a Customer Credit Agreement document using PDFSharp. It all looks fantastic but when I get the 3 unique signatures from the SQL database and DrawImage(FromStream) them on the document, whichever one I draw first is then repeated for the other 2. If I change the order of the DrawImage statements, I get a different signature, but again, repeated. For my sanity, I tried saving the 3 streams to disk and there I can see that they are all different. Now here's another pointer (hopefully)... Even though I can see that the 3 images on disk are different, if I then use DrawImage(FromFile) for the 3 images, the same problem occurs. I.e. Whichever image is drawn first is repeated for the other 2. So in my mind, it's like any image that originated from a stream, even after saving to disk, is seen as the same image and therefore maybe taken from cache or something like that. I do hope this helps you. And if there's anything I can provide to assist, please let me know. Thank you. |
For issue reporting, see here: It should be easy to replicate the issue without MVC in a console application. |
Thank you. Here's a quick update that may help... |
It would be good to have code that allows to replicate the issue. |
Again, thank you for your fast responses. |
This link works: This link works: |
Unfortunately not for me... (Maybe I'm doing something wrong) https://docs.pdfsharp.net/General/Issue-Reporting.html takes me to a page with a link to https://github.com/empira/PDFsharp.IssueSubmissionTemplate. Further down this page is this...
Which is the same page. However, when I click it I can see the URL trying to change to something else before just refreshing the current page. Anyway, back to the real issue. I will try now to create a console project that I can send over and some images. Thank you. |
Try this page: Near the top is a green button labelled "<> Code" with a drop-down menu. The drop-down menu gives you several options to get the code, including "Download ZIP", or "Clone" with "GitHub CLI", or copy the "HTTPS" link to clone with Visual Studio - to name just a few options. |
I now understand. It's a whole project. For some reason I was expecting some kind of web form. Sorry. |
Thank you. I know I need to get myself familiar with how GitHub works and how I can get your fix into my project so that I can try it. However, I am hoping that the attached ZIP in my reply to @ThomasHoevel will help locate the problem and version 6.1.2 will be released soon. Fingers crossed. |
@X1WGM I can replicate the issue now. Will talk to my boss about a 6.1.2 version. Maybe we'll skip 6.1.2 and go for 6.2.0 Preview 1 instead. The change from PR 128 does not make a difference in this case, so not worth giving it a try. |
Hello @ThomasHoevel, The images were created from a byte array. Here is the process of the web app that I have created...
What I did for testing this was save the streams to disk, I.e. Image1.png, Image2.png & Image3.png. As you can see in my example project the 3 images are different when viewed on the file system. But when these are added to the document, the first image used is then duplicated for the other images. I have cunningly found a work-around for now. That is... If I resize the 3 images to different dimensions but keeping the aspect ratio, they all work as expected. In my testing, even a resize back to the original size causes them to duplicate the first image. So it's like it is caching the first images dimensions and then any subsequent images of the same size get ignored and the first image is used. That's just what I have found. I hope this helps. Anyway, fantastic software. Our credit agreements are looking neat and professional. Thank you. 👍👍👍 |
The issue submitted by X1WGM is different from the issue submitted by Andreas.
See also: |
Here's a workaround that doesn't require building the entire library from source, nor making any modifications to the content of images: var image = XImage.FromStream(stream);
// HACK: Workaround https://github.com/empira/PDFsharp/issues/127
var selectorField = image.GetType().GetField("_selector", BindingFlags.Instance | BindingFlags.NonPublic);
var selector = Activator.CreateInstance(selectorField.FieldType, image, doc.Options);
selector.GetType().GetField("<Path>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(selector, Guid.NewGuid().ToString());
selectorField.SetValue(image, selector);
// END HACK: Workaround https://github.com/empira/PDFsharp/issues/127
|
This workaround seems to work perfectly as a temporary solution. When using this code, it was a bit unclear what the |
Thanks for this fix. |
I want to clarify one point: The issue discussed here occurs if two images have identical pixels when the only differences are in the mask. The sample images we have seen consist of black pixels only, stored in RGB format using 24 bits per pixel. It would save memory to store those all-black images in monochrome format with just 1 bit per pixel, but that's a different story. The alpha mask finally leads to a grayscale image. I did not expect that applications would use all-black images with identical dimensions where the only differences are in the masks. The workaround above is a workaround, not a fix. It disables the detection of identical images and should only be used if you are affected by this issue. Another workaround is changing the image dimensions. If you have e.g. four static images that are all 320 pixels wide, then consider changing one image to 321 pels, one to 322 pels, one to 323 pels width. Images will then be added to the PDF only once, even if they are used multiple times on the same or different pages. |
Issue should be resolved with PDFsharp 6.2.0 Preview 2. |
!!!!! If you think there is a bug in PDFsharp then please use the IssueSubmissionTemplate to make the issue replicable.
!!!!! https://docs.pdfsharp.net/General/IssueReporting.html
!!!!! => Sorry, but this link doesn't work
Reporting an Issue Here
When creating an PDF with three different Images, using XGraphics.DrawImage, the resulting PDF schould show up three different images.
Actual Behavior
The resulting pdf shows up the same (first) image for three times.
This happend, if PDFSharp 6.1.0 is used
This does not happen, if PDFSharp 6.0.0 is used.
Steps to Reproduce the Behavior
!!!!! We strongly recommend using the IssueSubmissionTemplate to make sure we can replicate the issue.
!!!!! https://docs.pdfsharp.net/General/IssueReporting.html
!!!!! => sorry, this link does not work.
Download Solution from embedded zip File.
Compile Solution using NuGet Package PDFSharp6.1.0
Run the compiled Program. This will produce the wrong result.
(file PdfSharpTest1.pdf in the Solution Folder)
Compile Solution using NuGet Package PDFSharp6.0.0
Run the compiled Program. This will produce the correct result.
(file PdfSharpTest1.pdf in the Solution Folder)
PdfSharpTest1.zip
This sample project contains 2 PDF Files. These are the results when Project is compiled with PDFSharp 6.0.0 oder PDFSharp 6.1.0
The PDF named PdfSharpTest1-Version6.0.0.pdf contains the expected result.
The PDF named PdfSharpTest1-Version6.1.0.pdf contains the wrong result.
The text was updated successfully, but these errors were encountered: