Portfolio Capture Example

compared with
Current by Patrick Corless
on Mar 13, 2017 08:45.

These lines were removed. This word was removed.
These lines were added. This word was added.

View page history

There are 1 changes. View first change.

 h3. 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:
  The source-code for this example is located at:
 * [http://sventon.icesoft.org/svn/repos/repo/list/icepdf/trunk/icepdf/examples/capture/portfolio/].
 A primer on using Maven or Gradle build commands can be found [here (Maven)| http://www.icesoft.org/wiki/display/PDF/Maven+Build] and [here (Gradle)| http://www.icesoft.org/wiki/display/PDF/Gradle+Build]
 // open the url
 Document document = new Document();
 // setup threads to handle image capture.
 ExecutorService executorService = Executors.newFixedThreadPool(8);
 // 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.submit(new DocumentCloser(document)).get();

© Copyright 2017 ICEsoft Technologies Canada Corp.