This demo uses the DevExpress PDF Document API (PdfDocumentProcessor) to remove certain types of content from document pages. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Select the content types to clear and specify the Page Range Settings. Click Clear Pages to update the document and download the result.
Select a Document
Sample_Main.pdf
Text
Images
Graphics
Annotations
Page Range Settings
using DevExpress.Pdf;
Stream ClearPages(Stream documentStream, bool clearAnnotations, bool clearGraphics,
bool clearImages, bool clearText, IEnumerable<int> pageRange) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
if(!pageRange.Any())
pageRange = Enumerable.Range(0, processor.Document.Pages.Count);
foreach(var index in pageRange) {
if(index < 0 || index >= processor.Document.Pages.Count)
continue;
var page = processor.Document.Pages[index];
var options = new PdfClearContentOptions() {
ClearAnnotations = clearAnnotations,
ClearGraphics = clearGraphics,
ClearImages = clearImages,
ClearText = clearText
};
processor.DocumentFacade.Pages[index].ClearContent(page.MediaBox, options);
}
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
return outputStream;
}