|PDFsharp & MigraDoc Foundation
|Remove all images from a PdfPage
|Page 1 of 1|
|Author:||Xifried [ Tue Apr 08, 2014 6:39 am ]|
|Post subject:||Remove all images from a PdfPage|
I use the PdfSharp library (1.32.2608.0) as part of a winforms-project to delete all images from a PdfPage.
When I save the document, the file-size has shrinked to a minimum (cool - that was what I tried to achieve) but when I open the document I get an error (or more an info) from the acrobat reader which tells me that there is an error on the page and that the page might not work correctly, although everything is displayed fine when I click the OK-button. Anyway, my customers shall not get that message when they open the document.
To identify the images on a page I used the code provided with the ExportImages Sample.
Before I start removing images I create a catalog with all images that are part of the whole document and a list of the pages were they get referenced.
Then I iterate all images of the page.
If the current image is not used on another page then I remove it:
PdfDictionary xObjects = resources.Elements.GetDictionary("/XObject");
PdfReference reference = item as PdfReference;
document.Internals.RemoveObject((PdfObject)reference.Value); // remove image from internal document table
xObjects.Elements.Remove(itemKey); // remove image from page resource
It seems that I somehow corrupt the pdf-file with my code.
If someone has a clean solution for this issue, it would be really cool!
|Author:||finnce [ Thu Oct 07, 2021 1:18 am ]|
|Post subject:||Re: Remove all images from a PdfPage|
I have this question also.
Could someone please help?
|Page 1 of 1||All times are UTC|
|Powered by phpBB® Forum Software © phpBB Group