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 Mar 28, 2018 1:09 pm

Hello

I have just purchased Spire.PDF and I have two urgent problems.

1. When using page.ReplaceImage, the new image is resized to fit the same space the original image used. This means that the new image is stretched or shrunk disproportionately and the look of the image isn't usable. How can I resize the new replaced image?

2. When I used page.DeleteImage, all the content from the page is removed along with the image.

I have an urgent deadline to fix this please. The tool I am building will be used on a large set of PDF files.

The version is 4.3.4.

desowen
 
Posts: 1
Joined: Tue Jan 30, 2018 12:58 pm

Thu Mar 29, 2018 6:46 am

Hello,

Thanks for your inquiry.
Answer 1, I'm sorry there is no way to resize the new replaced image. Here is a solution can get the result you want, that is drawing the new image in the specific place where the original image locates, and then deleting the original image. Please refer to below sample code.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Sample.pdf");
PdfPageBase page = doc.Pages[0];
PdfImage image = PdfImage.FromFile("NewImage.png");

float x = page.ImagesInfo[0].Bounds.Location.X;
float y = page.ImagesInfo[0].Bounds.Location.Y;

//Draw the new image
page.Canvas.DrawImage(image, x, page.ActualSize.Height - y - page.ImagesInfo[0].Bounds.Height, image.Width, image.Height);

//Delete the original image 
page.DeleteImage(0);
           
doc.SaveToFile("Result.pdf", FileFormat.PDF);

Answer 2, I tested the DeleteImage method but didn't encounter the issue you mentioned. To help us investigate it, please provide your input Pdf file. You could send it to us via email support@e-iceblue.com.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Mon Apr 02, 2018 9:47 am

Hello,

Greetings from E-iceblue!
How is your issue now?
Your feedback will be greatly appreciated.

Best wishes,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF