Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Oct 12, 2022 5:34 pm

After we stamp pdf page with image we can see that image is losing a lot on quality in the document compering with original. We are using PdfRubberStampAnnotation for adding image to a page of pdf document. We are using Spire.pdf licensed version 8.7.2. Do you have some idea how to keep quality on stamping document?

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Thu Oct 13, 2022 10:33 am

Hello,

Thanks for your inquiry.
I simulated a Pdf document and image with the latest version of Spire.Pdf (Spire.Pdf 8.9.16) to test your scenario, but I didn’t reproduce your issue. Please update to the latest version of Spire.Pdf and have a test, if the issue still exists, please offer the following message, thanks for your assistance in advance.
1) Your input Pdf document and image, you can attach them here or sent them to us via email([email protected] ).
2) Your full test code that can reproduce your issue.
3) Application type, such as Console App, .NET Framework 4.8.
4) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Oct 14, 2022 11:32 am

We need to resize image so it fit a PdfRubberStampAnnotation rectangle dimensions , if image is bigger only part is visible in stamp. Is there some option that we can use to fit the image to rectangle or we need to manipulate image size before we use it for stamping document?

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Mon Oct 17, 2022 11:04 am

Hello,

Thanks for your feedback.
You can reset size of image with the following code snippet:


Code: Select all
 //Load image as stamp
            PdfImage image = PdfImage.FromFile(@"../../data/test.jpg");

            //Reset size of image
            float width = image.Width*0.2f;
            float height = image.Height*0.2f;


And I put the complete code below for your reference:
Code: Select all
//Load pdf document
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);

            //Get the first page of Pdf document
            PdfPageBase page = doc.Pages[0];     
           
            //Load image as stamp
            PdfImage image = PdfImage.FromFile(@"../../data/test.jpg");

            //Reset size of image
            float width = image.Width*0.2f;
            float height = image.Height*0.2f;

            //Create a new PdfRubberStampAnnotation object and specifies the location and size of its annotation
            PdfRubberStampAnnotation loStamp = new PdfRubberStampAnnotation(new RectangleF(new PointF(0, 0), new SizeF(width, height)));

            //Instantiate a PdfAppearance object and load the image as the stamp
            PdfAppearance loApprearance = new PdfAppearance(loStamp);

            //Create a new PDF template and draw images in the template
            PdfTemplate template = new PdfTemplate(width, height, true);
            template.Graphics.DrawImage(image,0,0,width,height);
            loApprearance.Normal = template;
            loStamp.Appearance = loApprearance;

            //Add stamp to Pdf document
            page.AnnotationsWidget.Add(loStamp);

            //Save the result document
            doc.SaveToFile(@"../../output/result2.pdf",FileFormat.PDF);

If you have any other issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Oct 18, 2022 7:49 am

Thank you , this was helpful .

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Tue Oct 18, 2022 8:06 am

Hello,

Thanks for your feedback.
If you have any issue, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF

cron