Portfolio Capture Example

You are viewing an old version (v. 6) of this page.
The latest version is v. 7, last edited on Mar 13, 2017 (view differences | )
<< View previous version | view page history | view next version >>

About the Portfolio Capture Example

The Portfolio (Collections) Capture example demonstrates how to use the ICEpdf Document class to capture PDF page renders as image files of all documents that are contained in the collection. Once a file has been opened, the documents and pages can be iterated over, to generate an image capture of each page.

The source-code for these examples is located at:

A primer on using Maven or Gradle build commands can be found here (Maven) and here (Gradle)

// open the url
Document document = new Document();

// setup threads to handle image capture.
ExecutorService executorService = Executors.newFixedThreadPool(8);
document.setFile(filePath);
// A fileNames tree indicates that we have a portfolio.
if (document.getCatalog().getNames() != null &&
        document.getCatalog().getNames().getEmbeddedFilesNameTree() != null && 
        catalog.getNames().getEmbeddedFilesNameTree().getRoot() != null) {
    NameTree embeddedFilesNameTree = document.getCatalog().getNames().getEmbeddedFilesNameTree();
    // one final check as some docs will have meta data but will specify a page mode.
    if (catalog.getObject(Catalog.PAGEMODE_KEY) == null ||
                ((Name) catalog.getObject(Catalog.PAGEMODE_KEY)).getName().equalsIgnoreCase("UseAttachments")) {
        if (embeddedFilesNameTree.getRoot() != null) {
            Library library = document.getCatalog().getLibrary();
            List filePairs = embeddedFilesNameTree.getRoot().getNamesAndValues();
            List<Callable<Void>> callables =
                    new ArrayList<Callable<Void>>(filePairs.size() / 2);
            // queue up the embedded documents
            for (int i = 0, max = filePairs.size(); i < max; i += 2) {
                // file name and file specification pairs.
                String fileName = Utils.convertStringObject(library, (StringObject) filePairs.get(i));
                HashMap tmp = (HashMap) library.getObject((Reference) filePairs.get(i + 1));

               // file specification has the document stream
               FileSpecification fileSpec = new FileSpecification(library, tmp);
               tmp = fileSpec.getEmbeddedFileDictionary();

               // create the stream instance from the embedded file streams File entry.
               Reference fileRef = (Reference) tmp.get(FileSpecification.F_KEY);
               Stream fileStream = (Stream) library.getObject(fileRef);
               InputStream fileInputStream = fileStream.getDecodedByteArrayInputStream();

               // queue the embedded document for page capture
               System.out.println("Loading embedded file: " + fileName);
               Document embeddedDocument = new Document();
               embeddedDocument.setInputStream(fileInputStream, fileName);
               callables.add(new CaptureDocument(embeddedDocument, i, fileName));
           }
           executorService.invokeAll(callables);
           executorService.submit(new DocumentCloser(document)).get();
        }
    }
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.