0
PDFSharpを使用して既存のPDFから画像(すべて)を削除するにはどうすればよいですか?PDFSharpを使用してpdfから画像を削除するには?
私はこのコードを試してみました:?
public static PdfDocument RemoveImages(PdfDocument pdf)
{
foreach (PdfPage page in pdf.Pages)
{
PdfDictionary resource = page.Elements.GetDictionary("/Resources");
if (resource != null)
{
PdfDictionary objects = resource.Elements.GetDictionary("/XObject");
if (objects != null)
{
foreach (string itemKey in objects.Elements.Keys)
{
PdfItem item = objects.Elements[itemKey];
PdfReference reference = item as PdfReference;
if (reference != null)
{
PdfDictionary xObject = reference.Value as PdfDictionary;
if (xObject != null && xObject.Elements.GetString("/Subtype") == "/Image")
{
pdf.Internals.RemoveObject((PdfObject)reference.Value); // remove image from internal document table
objects.Elements.Remove(itemKey); // remove image from page resource
}
}
}
}
}
}
return pdf;
}
しかし、このコードは時にAcrobat Readerで開いているファイル...
がどのように私はcurruptionなしPDFSharpを使用して、既存のPDFファイルから画像を削除することができたPDF curruptionを提供
ありがとうございます!