Using the BI Publisher Java APIs 7-21
7.7.1.2 Merging PDF Documents with InputOutput Streams
Input:
■
PDF Documents InputStream Array Output:
■
PDF Document OutputStream
Example 7–23 Merging PDF Documents with InputOutput Streams
import java.io.; import oracle.xdo.common.pdf.util.PDFDocMerger;
. .
. public boolean mergeDocsInputStream[] inputStreams, OutputStream outputStream
{ try
{ Initialize PDFDocMerger
PDFDocMerger docMerger = new PDFDocMergerinputStreams, outputStream;
Merge PDF Documents and generates new PDF Document docMerger.mergePDFDocs;
docMerger = null; return true;
} catchException exc
{ exc.printStackTrace;
return false; }
}
7.7.1.3 Merging with Background to Place Page Numbering
The following code demonstrates how to merge two PDF documents using input streams to generate a single merged output stream.
To add page numbers:
1.
Create a background PDF template document that includes a PDF form field in the position that you would like the page number to appear on the final output PDF
document.
2.
Name the form field pagenum.
3.
Enter the number in the field from which to start the page numbering. If you do not enter a value in the field, the start page number defaults to 1.
Input:
■
PDF Documents InputStream Array
■
Background PDF Document InputStream Output:
■
PDF Document OutputStream
7-22 Developers Guide for Oracle Business Intelligence Publisher
Example 7–24 Sample Code for Merging PDF Documents with Background to Place
Page Numbering
import java.io.; import oracle.xdo.common.pdf.util.PDFDocMerger;
. .
. public static boolean mergeDocsInputStream[] inputStreams, InputStream
backgroundStream, OutputStream outputStream
{ try
{ Initialize PDFDocMerger
PDFDocMerger docMerger = new PDFDocMergerinputStreams, outputStream; Set Background
docMerger.setBackgroundbackgroundStream;
Merge PDF Documents and generates new PDF Document docMerger.mergePDFDocs;
docMerger = null; return true;
} catchException exc
{ exc.printStackTrace;
return false; }
}
7.7.1.4 Adding Page Numbers to Merged Documents
The FO Processor supports page numbering natively through the XSL-FO templates, but if you are merging multiple documents you must use this class to number the
complete document from beginning to end.
The following code example places page numbers in a specific point on the page, formats the numbers, and sets the start value using the following methods:
■
setPageNumberCoordinates x, y - sets the x and y coordinates for the page number position. The following example sets the coordinates to 300, 20.
■
setPageNumberFontInfo font name, size - sets the font and size for the page number. If you do not call this method, the default Helvetica, size 8 is used. The
following example sets the font to Courier, size 8.
■
setPageNumberValue n, n - sets the start number and the page on which to begin numbering. If you do not call this method, the default values 1, 1 are used.
Input:
■
PDF Documents InputStream Array Output:
■
PDF Document OutputStream
Using the BI Publisher Java APIs 7-23
Example 7–25 Sample Code for Adding Page Numbers to Merged PDF Documents
import java.io.; import oracle.xdo.common.pdf.util.PDFDocMerger;
. .
. public boolean mergeDocsInputStream[] inputStreams, OutputStream outputStream
{ try
{ Initialize PDFDocMerger
PDFDocMerger docMerger = new PDFDocMergerinputStreams, outputStream;
Calls several methods to specify Page Number Calling setPageNumberCoordinates method is necessary to set Page
Numbering Please refer to javadoc for more information
docMerger.setPageNumberCoordinates300, 20;
If this method is not called, then the default fontHelvetica, 8 is used.
docMerger.setPageNumberFontInfoCourier, 8;
If this method is not called, then the default initial value 1, 1 is used.
docMerger.setPageNumberValue1, 1;
Merge PDF Documents and generates new PDF Document docMerger.mergePDFDocs;
docMerger = null; return true;
} catchException exc
{ exc.printStackTrace;
return false; }
}
7.7.2 Setting a Text or Image Watermark
Some documents that are in a draft phase require that a watermark indicating DRAFT be displayed throughout the document. Other documents might require a
background image on the document. The following code sample shows how to use the PDFDocMerger class to set a watermark.
7.7.2.1 Setting a Text Watermark
Use the SetTextDefaultWatermark method to set a text watermark with the following attributes:
■
Text angle in degrees: 55
■
Color: light gray 0.9, 0.9, 0.9
■
Font: Helvetica
7-24 Developers Guide for Oracle Business Intelligence Publisher
■
Font Size: 100
■
The start position is calculated based on the length of the text Alternatively, use the SetTextWatermark method to set each attribute separately. Use
the SetTextWatermark method as follows:
■
SetTextWatermark Watermark Text, x, y - declare the watermark text, and set the x and y coordinates of the start position. In the following example, the
watermark text is Draft and the coordinates are 200f, 200f.
■
setTextWatermarkAngle n - sets the angle of the watermark text. If this method is not called, 0 will be used.
■
setTextWatermarkColor R, G, B - sets the RGB color. If this method is not called, light gray 0.9, 0.9, 0.9 will be used.
■
setTextWatermarkFont font name, font size - sets the font and size. If you do not call this method, Helvetica, 100 will be used.
The following example shows how to set these properties and then call the PDFDocMerger.
Input:
■
PDF Documents InputStream Output:
■
PDF Document OutputStream
Example 7–26 Sample Code for Setting a Text Watermark in PDF Documents
import java.io.; import oracle.xdo.common.pdf.util.PDFDocMerger;
. .
. public boolean mergeDocsInputStream inputStreams, OutputStream outputStream
{ try
{ Initialize PDFDocMerger
PDFDocMerger docMerger = new PDFDocMergerinputStreams, outputStream;
You can use setTextDefaultWatermark without these detailed setting docMerger.setTextWatermarkDRAFT, 200f, 200f; set text and place
docMerger.setTextWatermarkAngle80; set angle docMerger.setTextWatermarkColor1.0f, 0.3f, 0.5f; set RGB Color
Merge PDF Documents and generates new PDF Document docMerger.mergePDFDocs;
docMerger = null; return true;
} catchException exc
{ exc.printStackTrace;
return false; }
}
Using the BI Publisher Java APIs 7-25
7.7.2.2 Setting Image Watermark
An image watermark can be set to cover the entire background of a document, or just to cover a specific area for example, to display a logo. Specify the placement and size
of the image using rectangular coordinates as follows:
float[] rct = {LowerLeft X, LowerLeft Y, UpperRight X, UpperRight Y}
For example: float[] rct = {100f, 100f, 200f, 200f}
The image will be sized to fit the rectangular area defined. To use the actual image size, without sizing it, define the LowerLeft X and LowerLeft
Y positions to define the placement and specify the UpperRight X and UpperRight Y coordinates as -1f. For example:
float[] rct = {100f, 100f, -1f, -1f} Input:
■
PDF Documents InputStream
■
Image File InputStream Output:
■
PDF Document OutputStream
Example 7–27 Sample Code for Setting an Image Watermark in PDF Documents
import java.io.; import oracle.xdo.common.pdf.util.PDFDocMerger;
. .
. public boolean mergeDocsInputStream inputStreams, OutputStream outputStream,
String imageFilePath {
try {
Initialize PDFDocMerger PDFDocMerger docMerger = new PDFDocMergerinputStreams, outputStream;
FileInputStream wmStream = new FileInputStreamimageFilePath; float[] rct = {100f, 100f, -1f, -1f};
pdfMerger.setImageWatermarkwmStream, rct;
Merge PDF Documents and generates new PDF Document docMerger.mergePDFDocs;
docMerger = null; Closes inputStreams
return true; }
catchException exc {
exc.printStackTrace; return false;
} }
7-26 Developers Guide for Oracle Business Intelligence Publisher
7.8 PDF Bookbinder Processor
The PDFBookBinder processor is useful for the merging of multiple PDF documents into a single document consisting of a hierarchy of chapters, sections, and subsections
and a table of contents for the document. The processor also generates PDF style bookmarks; the outline structure is determined by the chapter and section hierarchy.
The processor is extremely powerful allowing you complete control over the combined document.
7.8.1 Usage
The table of contents formatting and style is defined by an RTF template created in Microsoft Word. The chapters are passed into the program as separate PDF files one
chapter, section, or subsection corresponds to one PDF file. Templates may also be specified at the chapter level for insertion of dynamic or static content, page
numbering, and placement of hyperlinks within the document.
The templates can be in RTF or PDF format. RTF templates are more flexible by allowing you to leverage BI Publishers support for dynamic content. PDF templates
are much less flexible, making it difficult to achieve desirable effects such as the reflow of text areas when inserting page numbers and other types of dynamic content.
The templates can be rotated at right angles or be made transparent. A PDF template can also be specified at the book level, enabling the ability to specify global page
numbering, or other content such as backgrounds and watermarks. You can also pass as parameters a title page, cover page, and closing pages for each chapter or section.
7.8.2 XML Control File
The structure of the books chapters, sections, and subsections is represented as XML and passed in as a command line parameter; or it can also be passed in at the API
level. All of the chapter and section files, and all the templates files and their respective parameters, are specified inside this XML structure. Therefore, the only two
required parameters are an XML file and a PDF output file.
You can also specify volume breaks inside the book structure. Specifying volume breaks will split the content up into separate output files for easier file and printer
management.
The structure of the XML control file is represented in the following diagram:
Using the BI Publisher Java APIs 7-27
Figure 7–5 Structure of XML Control File
To specify template and content file locations in your XML structure, you can specify a path relative to your local file system or you can specify a URL referring to the
template or content location. Secure HTTP protocol is supported, as are specially recognized BI Publisher protocols, such as:
■
xdoxsl: used to load subtemplate.
■
xdo: - used to load other resources such as images.
7.8.3 Command Line Options
Following is an example of the command line usage:
Example 7–28 Sample of Command Line Options
java oracle.xdo.template.pdf.book.PDFBookBinder [-debug true or false] [-tmp temp dir] -xml input xml -pdf output pdf
where -xml file is the file name of the input XML file containing the table of contents
XML structure. -pdf file is the final generated PDF output file.
7-28 Developers Guide for Oracle Business Intelligence Publisher
-tmp directory is the temporary directory for better memory management. This is optional, if not specified, the system environment variable
java.io.tmpdir will be used.
-log file sets the output log file optional, default is System.out. -debug true or false turns debugging off or on.
7.8.4 API Method Call
The following is an example of an API method call:
Example 7–29 Sample API Method Call
String xmlInputPath = c:\\tmp\\toc.xml; String pdfOutputPath = c:\\tmp\\final_book.pdf;
PDFBookBinder bookBinder = new PDFBookBinderxmlInputPath, pdfOutputPath;
bookBinder.setConfignew Properties; bookBinder.process;
7.9 PDF Digital Signature Engine
This section discusses how to use the PDF Digital Signature Engine, and includes the following topics:
■
Section 7.9.1, Overview of the PDF Digital Signature Engine
■
Section 7.9.2, Signing PDF Documents
■
Section 7.9.3, Delivering Signed PDF Documents.
■
Section 7.9.4, Verifying Signed PDF Documents
7.9.1 Overview of the PDF Digital Signature Engine
The PDF Digital Signature Engine creates signed PDF documents by processing unsigned PDF documents with a signature field name and a password-protected
Personal Information Exchange PFX file. PFX files adhere to the Public Key Cryptography Standards 12 PCKS-12 format and contain a digital certificate and a
corresponding private key.
To create signed PDF documents, see Section 7.9.2, Signing PDF Documents.
To distribute or deliver signed PDF documents, use the Schedule Service. See Chapter 3, ScheduleService.
To verify signed PDF documents, see Section 7.9.4, Verifying Signed PDF Documents.
7.9.2 Signing PDF Documents
Signing a PDF document requires the following items:
■
A digital certificate. To obtain a digital certificate, see Implementing Digital Signatures in Oracle Fusion Middleware Developers Guide for Oracle Business
Intelligence Publisher.
■
A PFX file that contains your digital certificate.To create a PFX file, see Implementing Digital Signatures in Oracle Fusion Middleware Developers Guide for
Oracle Business Intelligence Publisher.