Not yet rated

Problem

The default view for PDF documents created in your organization is the Bookmarks panel open view. Visually this is not very appealing for documents that are only one page. A process is required that determines how many pages are in a document and then applies a different view based on that number.

Solution

In place of adding a watched folder on top of the GeneratePDFService of PDFg to generate a PDF from incoming documents, we need to create a simple process that will allow us to change the value of the initial view of the document based on the number of pages in it.

Detailed explanation

The PDF Generator service is required to first convert the incoming document into PDF. Once the initial PDF is created the AssemblerService can be called requesting the "DocumentInformation" data that will provide us with the number of pages in the document.
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="http://ns.adobe.com/DDX/1.0/">
     <DocumentInformation result="info.xml" source="inDoc1"/>
</DDX>
When this DDX code is applied to the document the resulting assembler log will contain the XML details we need to obtain the page numbers. This is retrieved from the assembler result variable used, in this case, /process_data/ThePDFAssemblerResult/object/documents[1]. We are not generating a new PDF at this point, we're simply gathering the information about the current PDF.
Following the Assembler invocation the DocInfo document is retrieved from the Assembler result - /process_data/ThePDFAssemblerResult/object/documents[1]. In turn, the DocInfo XML object is then extracted from the /process_data/@AssemblerjobLog[1]. Finally, the actual number of pages can be read from the DocInfo XML variable - /process_data/DocInfo/DocInfo/NumPages. This can be done in-line but having the data exposed as a variable makes debugging and the reading of the process a little easier.
Now the page numbers are exposed, one of two sets of Assembler operations can be performed. The first with a "BookmarksPanel" view and the other with a "PageOnly" initial view pending on the number of pages in the PDF. These can be combined into a single operation with the DDX being built on the fly via an xPath expression but the separated calls allows for a better visual representation of what is going to occur depending on the circumstances.
To apply the bookmark initial view we run the following DDX on the document:
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="http://ns.adobe.com/DDX/1.0/">
     <PDF result="outDoc1" initialView="bookmarks"
save="FastWebView">
          <PDF source="inDoc1"/>
     </PDF>
     <InitialViewProfile name="bookmarks" show="BookmarksPanel"
magnification="Default" openToPage="1"/>
</DDX>
To apply the page only initial view we run the following DDX on the document. As you can see, these can be combined into a single DDX operation replacing the initialView hard-coded "pageonly" with an xPath variable:
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="http://ns.adobe.com/DDX/1.0/">
     <PDF result="outDoc1" initialView="pageonly"
save="FastWebView">
          <PDF source="inDoc1"/>
     </PDF>
     <InitialViewProfile name="pageonly" show="PageOnly"
magnification="Default" openToPage="1"/>
</DDX>
The attached sample is an extension to the "ConvertAllFileTypesToPDF - 1.0" example included in the LiveCycle ES installation. It also includes the use of the PDFUtilityService to retrieve additional information about the PDF so you can compare the use of this service version the DDX operations. 

Process Screen Shot

Configuring the watched folder on this process requires "%E" for the fileExtension variable, "%F" for the fileName , and "*" for the inputDocument.  Optionally you can enter "%F_%E.pdf " for the output variable.

Watched Folder Configuration

 

LCES_8.2.1-Changing_Initial_View_Based_on_Number_of_Pages_in_a_PDF.zip
[Changing Initial View Based on Number of Pages in a PDF]
ddx_use_screen_shot.jpg
[Process Screen Shot]
watched_folder_screen_shot.jpg
[Watched Folder Configuration]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes