Example usage for org.apache.pdfbox.pdmodel PDDocument removePage

List of usage examples for org.apache.pdfbox.pdmodel PDDocument removePage

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDDocument removePage.

Prototype

public void removePage(int pageNumber) 

Source Link

Document

Remove the page from the document.

Usage

From source file:org.oscarehr.document.web.SplitDocumentAction.java

License:Open Source License

public ActionForward removeFirstPage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Document doc = documentDAO.getDocument(request.getParameter("document"));

    //      String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
    String docdownload = EDocUtil.getDocumentPath(doc.getDocfilename());

    //      FileInputStream input = new FileInputStream(docdownload + doc.getDocfilename());
    FileInputStream input = new FileInputStream(docdownload);
    PDFParser parser = new PDFParser(input);
    parser.parse();// w w  w. j a va 2  s  . c om
    PDDocument pdf = parser.getPDDocument();

    // Documents must have at least 2 pages, for the first page to be removed.
    if (pdf.getNumberOfPages() <= 1) {
        return null;
    }

    int x = 1;
    for (Object p : pdf.getDocumentCatalog().getAllPages()) {
        ManageDocumentAction.deleteCacheVersion(doc, x);
        x++;
    }

    pdf.removePage(0);

    EDocUtil.subtractOnePage(request.getParameter("document"));

    //      pdf.save(docdownload + doc.getDocfilename());
    System.gc(); //avoid Win channel lock problem
    pdf.save(docdownload);
    pdf.close();

    input.close();

    return null;
}

From source file:serock.pdfpagerestorer.PdfPageRestorer.java

License:Open Source License

private static void removePages(final PDDocument pdDoc) {
    final int numberOfPages = pdDoc.getNumberOfPages();
    for (int i = numberOfPages - 1; i >= 0; i--) {
        pdDoc.removePage(i);
    }/*from  w ww  .ja v  a2  s. c o m*/
}

From source file:src.controller.DocumentController.java

/**
 * Supprime la page spcifie d'un document
 * @param document/* w w w  .  j  ava  2  s.c  om*/
 * @param id 
 */
public void removePage(PDDocument document, int id) {
    if (document.getNumberOfPages() > 1) {
        document.removePage(id);
    } else {
        System.out.println(TRANSLATOR.getString("PAGE_DELETE_FAIL"));
    }
}