Using compound documents, you can make a single PrizmDoc® for Java document composed of multiple files of different formats. For example, if you provide a PDF and an image file in that order, PrizmDoc® for Java will treat it as one document with the image file as the last page. This can be useful to display different files as one for convenience - for example, a cover letter and resume could be displayed as the first and second page, or an incident form could have evidence photos attached as following pages.

Document modifications, such as rotating or inserting/deleting pages, cannot be done to a compound document without converting it to a single-file document (either a PDF or a TIF, depending on if the first content element was a text or image file). This is handled automatically by PrizmDoc for Java.

Note: media such as video or audio files cannot be part of a compound document. Media must be returned as a single standalone content element.

Loading and displaying Compound Documents

Compound documents are constructed in the content handler method getDocumentContent(). To return a compound document, return several content elements in the KEY_DOCUMENT_CONTENT_ELEMENTS ContentHandlerResponse parameter. These content elements can be either a byte array, input stream, or File object. The types in the list do not have to all match. If only one content element is returned it will functionally be the same as a non-compound document composed of a single document format.

 // This example retrieves document content from the local file system and adds the same cover page to every 
 // requested document by returning them as a compound document.
 public ContentHandlerResult getDocumentContent(ContentHandlerInput input)
     throws VirtualViewerAPIException
 {
     String clientInstanceId = input.getClientInstanceId();
     String documentKey = input.getDocumentId();
     List<Object> contentElements = new List<Object>();
 
     //Adding the cover page first will make it the first page(s) of the document
     InputStream coverPage = getCoverPageStream();
     contentElements.put(coverPage);
 
     //Add the file content from the local system next
     String fullFilePath = gFilePath + URLDecoder.decode(documentKey);
     File file = new File(fullFilePath);
     byte[] fileBytes = com.snowbound.common.utils.ClientServerIO.getFileBytes(file);
     contentElements.put(fileBytes);
 
     ContentHandlerResult result = new ContentHandlerResult(); 
     result.put(ContentHandlerResult.KEY_DOCUMENT_CONTENT_ELEMENTS, contentElements);
     return result;
 }