Example usage for com.lowagie.text.pdf PdfReader close

List of usage examples for com.lowagie.text.pdf PdfReader close

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfReader close.

Prototype

public void close() 

Source Link

Document

Closes the reader

Usage

From source file:oscar.dms.actions.DocumentUploadAction.java

License:Open Source License

/**
 * Counts the number of pages in a local pdf file.
 * @param fileName the name of the file// w w  w. j av  a 2 s.co  m
 * @return the number of pages in the file
 */
public int countNumOfPages(String fileName) {// count number of pages in a
    // local pdf file
    int numOfPage = 0;
    //      String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
    //      String filePath = docdownload + fileName;
    String filePath = EDocUtil.getDocumentPath(fileName);

    try {
        PdfReader reader = new PdfReader(filePath);
        numOfPage = reader.getNumberOfPages();
        reader.close();
    } catch (IOException e) {
        logger.debug(e.toString());
    }
    return numOfPage;
}

From source file:oscar.oscarLab.ca.all.upload.handlers.PDFHandler.java

License:Open Source License

@Override
public String parse(LoggedInInfo loggedInInfo, String serviceName, String fileName, int fileId, String ipAddr) {

    String providerNo = "-1";
    String filePath = fileName;//from  www . ja va 2s  .  c o  m
    if (!(fileName.endsWith(".pdf") || fileName.endsWith(".PDF"))) {
        logger.error("Document " + fileName + "does not have pdf extension");
        return null;
    } else {
        int fileNameIdx = fileName.lastIndexOf("/");
        fileName = fileName.substring(fileNameIdx + 1);
    }

    EDoc newDoc = new EDoc("", "", fileName, "", providerNo, providerNo, "", 'A',
            oscar.util.UtilDateUtilities.getToday("yyyy-MM-dd"), "", "", "demographic", "-1", false);

    newDoc.setDocPublic("0");

    InputStream fis = null;

    try {
        fis = new FileInputStream(filePath);
        newDoc.setContentType("application/pdf");

        //Find the number of pages
        PdfReader reader = new PdfReader(filePath);
        int numPages = reader.getNumberOfPages();
        reader.close();
        newDoc.setNumberOfPages(numPages);

        String doc_no = EDocUtil.addDocumentSQL(newDoc);

        LogAction.addLog(providerNo, LogConst.ADD, LogConst.CON_DOCUMENT, doc_no, ipAddr, "", "DocUpload");

        //Get provider to route document to
        String batchPDFProviderNo = OscarProperties.getInstance().getProperty("batch_pdf_provider_no");
        if ((batchPDFProviderNo != null) && !batchPDFProviderNo.isEmpty()) {

            ProviderInboxRoutingDao providerInboxRoutingDao = (ProviderInboxRoutingDao) SpringUtils
                    .getBean("providerInboxRoutingDAO");
            providerInboxRoutingDao.addToProviderInbox(batchPDFProviderNo, Integer.parseInt(doc_no), "DOC");

            //Add to default queue for now, not sure how or if any other queues can be used anyway (MAB)                 
            QueueDocumentLinkDao queueDocumentLinkDAO = (QueueDocumentLinkDao) SpringUtils
                    .getBean("queueDocumentLinkDAO");
            Integer did = Integer.parseInt(doc_no.trim());
            queueDocumentLinkDAO.addToQueueDocumentLink(1, did);
        }
    } catch (FileNotFoundException e) {
        logger.info("An unexpected error has occurred:" + e.toString());
        return null;
    } catch (Exception e) {
        logger.info("An unexpected error has occurred:" + e.toString());
        return null;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (IOException e1) {
            logger.info("An unexpected error has occurred:" + e1.toString());
            return null;
        }
    }

    return "success";
}

From source file:papertoolkit.paper.bundles.PDFBundle.java

License:BSD License

/**
 * Reads the PDF file. For each page, create a new PDFSheet referencing that page. Add that
 * sheet to this bundle./*from   ww w.j a  v a  2 s. c  om*/
 */
private void addPDFSheetsFromFile() {
    try {
        final PdfReader reader = new PdfReader(new FileInputStream(file));
        numSheets = reader.getNumberOfPages();
        reader.close();
        for (int i = 0; i < numSheets; i++) {
            // (i+1) because Page Numbers start from 1
            addSheets(new PDFSheet(file, i + 1));
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:questions.forms.ReadXfa2.java

public static void main(String[] args) {
    try {/* w w w .  j  a  v a2  s  .c  om*/
        PdfReader reader = new PdfReader(RESOURCE);
        FileOutputStream os = new FileOutputStream(RESULT);
        XfaForm xfa = new XfaForm(reader);
        Document doc = xfa.getDomDocument();
        Transformer tf = TransformerFactory.newInstance().newTransformer();
        tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        tf.setOutputProperty(OutputKeys.INDENT, "yes");
        tf.transform(new DOMSource(doc), new StreamResult(os));
        reader.close();

    } catch (IOException e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
}