Skip to content
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

Does anyone know how to remove image from a PDF? #135

Closed
Charltsing opened this issue Jul 15, 2024 · 2 comments
Closed

Does anyone know how to remove image from a PDF? #135

Charltsing opened this issue Jul 15, 2024 · 2 comments
Labels
Cannot Reproduce https://xkcd.com/583/ forum Please use Discussions or the Support forum to ask Support questions - https://forum.pdfsharp.net/ support

Comments

@Charltsing
Copy link

Charltsing commented Jul 15, 2024

2.zip
Removed-err.zip

2

PdfDocument pdfDocument = PdfReader.Open("2.pdf", PdfDocumentOpenMode.Modify);
foreach (PdfPage page in pdfDocument.Pages)
{
    PdfResources resurce = page.Resources;
    PdfDictionary xobjects = (PdfDictionary)resurce.Elements["/XObject"];
    foreach (var xobject in xobjects.Elements)
    {
        if (xobject.Key == "\Im2") xobjects.Elements.Remove(xobject.Key);     
    }
}
pdfDocument.Save("2-new.pdf");
pdfDocument.Close();

PDF files that delete images in this way will report an error when opened

Does anyone know how to properly remove images from a PDF?

@ThomasHoevel
Copy link
Member

You also have to remove all references to "\Im2" from the content stream.

Please use Discussions or the Forum for that sort of questions.

@ThomasHoevel ThomasHoevel added support Cannot Reproduce https://xkcd.com/583/ forum Please use Discussions or the Support forum to ask Support questions - https://forum.pdfsharp.net/ labels Jul 15, 2024
@Charltsing
Copy link
Author

Charltsing commented Jul 15, 2024

You also have to remove all references to "\Im2" from the content stream.

Please use Discussions or the Forum for that sort of questions.

#136
How to get the contents stream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cannot Reproduce https://xkcd.com/583/ forum Please use Discussions or the Support forum to ask Support questions - https://forum.pdfsharp.net/ support
Projects
None yet
Development

No branches or pull requests

2 participants