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.
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:
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:
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.
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.