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

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

Introduction

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

Prototype

public PdfDictionary getPageNRelease(final int pageNum) 

Source Link

Usage

From source file:com.poet.ar.remover.AnnotationRemover.java

/**
 * @param fileIn  pdf filename you want to remove annotation
 * @param fileOut removed annotation pdf save path
 * @throws IOException// ww w .j  a  v a  2s. c  om
 * @throws DocumentException
 */
public static void doRemove(String fileIn, String fileOut) throws IOException, DocumentException {

    logger.debug("starting process file: " + fileIn);

    PdfReader reader = new PdfReader(fileIn);

    FileOutputStream fos = new FileOutputStream(fileOut);
    PdfStamper stamper = new PdfStamper(reader, fos);

    removeInfo(reader, stamper);

    int pageNums = reader.getNumberOfPages();

    int totalAnnoCount = 0;
    int totalContentCount = 0;
    for (int i = 1; i <= pageNums; i++) {

        PdfDictionary page = reader.getPageNRelease(i);

        int annoCount = doRemoveAnnotation(page);
        int contentCount = doRemoveContent(page);

        totalAnnoCount += annoCount;
        totalContentCount += contentCount;

        logger.debug("removed " + annoCount + " annotation(s) in page " + i + " ,in file: " + fileIn);
        logger.debug("removed " + contentCount + " content(s) in page " + i + " ,in file: " + fileIn);
    }

    stamper.close();
    fos.close();
    reader.close();

    logger.debug("success removed " + totalAnnoCount + " annotation(s), " + totalContentCount
            + " content(s), with output file: " + fileOut);
}