Example usage for com.itextpdf.text.pdf PdfReader getPageResources

List of usage examples for com.itextpdf.text.pdf PdfReader getPageResources

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfReader getPageResources.

Prototype

public PdfDictionary getPageResources(final PdfDictionary pageDict) 

Source Link

Document

Retrieve the given page's resource dictionary

Usage

From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java

License:Open Source License

private void cleanUpPage(int pageNum, List<PdfCleanUpLocation> cleanUpLocations)
        throws IOException, DocumentException {
    if (cleanUpLocations.size() == 0) {
        return;//from w w w  .j  a  v a  2 s.c  om
    }

    PdfReader pdfReader = pdfStamper.getReader();
    PdfDictionary page = pdfReader.getPageN(pageNum);
    PdfContentByte canvas = pdfStamper.getUnderContent(pageNum);
    byte[] pageContentInput = ContentByteUtils.getContentBytesForPage(pdfReader, pageNum);
    page.remove(PdfName.CONTENTS);

    canvas.saveState();

    PdfCleanUpRegionFilter filter = createFilter(cleanUpLocations);
    PdfCleanUpRenderListener pdfCleanUpRenderListener = new PdfCleanUpRenderListener(pdfStamper, filter);
    pdfCleanUpRenderListener.registerNewContext(pdfReader.getPageResources(page), canvas);

    PdfContentStreamProcessor contentProcessor = new PdfContentStreamProcessor(pdfCleanUpRenderListener);
    PdfCleanUpContentOperator.populateOperators(contentProcessor, pdfCleanUpRenderListener);
    contentProcessor.processContent(pageContentInput, page.getAsDict(PdfName.RESOURCES));
    pdfCleanUpRenderListener.popContext();

    canvas.restoreState();

    colorCleanedLocations(canvas, cleanUpLocations);

    if (redactAnnotIndirRefs != null) { // if it isn't null, then we are in "extract locations from redact annots" mode
        deleteRedactAnnots(pageNum);
    }
}