Declaration for LotusScript |
Start page Previous page Next page |
This document describes the basic technical principle underlying n2pdf (in Lotus Script) and defines a basic structure and sequence of events to be followed whenever PDFs are created. If you are interested in Java integration, you can find further information in the section Java Integration.
Besides integrating n2pdf using the "n2pdfDef.SCR" file (1) the following steps must also be performed when creating a PDF:
1. Initializing a new PDF File
You have to start a "job" in the main memory of the computer in order to create a PDF file with n2pdf. This is done using them command N2PDFInit (2). This command gives you an ID (Job ID) for the PDF file and generates the needed structures in the computer's memory. You should check this ID for validity (3) (see N2PDFInit), because it makes no sense to continue with the steps to create a PDF if it is not valid. Content and settings for the PDF file can only be defined after this first step has been completed.
2. Determining the PDF File Settings
In this next step you should make all the settings (4) for the PDF file using N2PDFSetOption and N2PDFSetGlobalOption. These could include, for example, the security settings for the PDF file as well as the configurations for automatically launching the viewer or generating the table of contents. Since some settings have a direct impact on the PDF file's content, you should always have made the settings before adding the initial content, e.g. using N2PDFAddContent.
3. Searching for Notes Content
Script programming must be used to find data for the PDF because n2pdf does not have its own mechanism for doing so. Using "standard" script programming, you will have to search for the documents or fields that you want to add to the PDF file as the main text, header/footer, variable or fields. Normally this will be a loop (5) cycling through various Notes documents whose content or individual fields you want to depict in a PDF. You can also work across databases or even with external data sources. The only requirement is that the data can be read out using script commands. Once you have completed this data selection, you can then insert the relevant n2pdf commands here as the next step and in so doing transfer the data into the PDF file.
4. Adding Content to the PDF
After you have found the Notes content in the preceding step, you can then use n2pdf commands to add the Notes documents or the individual fields to the PDF document. You can transfer unformatted fields (such as TEXT or NUMBER) or static texts into the PDF file (6), as well as Rich text fields and even entire documents. The first step is to define the headers and footers (6) (e.g. N2PDFAddContent) to be used in the PDF file. Then you should define the variables (7) (e.g. N2PDFAddVariable) and finally the PDF file's main text (8) (e.g. N2PDFAddRTContent), such as in a loop through all the documents.
5. Creating a PDF File
The last step is the creation of the PDF file (9), i.e. to generate a physical file from the PDF file located in the memory. In this step n2pdf executes all the settings that were made, formats the PDF according to your wishes, applies the structures (e.g. table of contents) to the PDF file and then writes the file from the memory into a physical file. When activating the function N2PDFProcess you must then specify a file name (10) to be used when the PDF file is created. This concludes the PDF creation and you can then send or e-mail the PDF file, display it in the viewer or file it as a new Notes document. All of LotusScript's features are now available to you should you want to do any further processing.
The simple script that follows illustrates all the steps described above needed to create a PDF file. The information enclosed in parentheses in red are references to the individual steps.
%INCLUDE "N2PDFDEF.SCR" ' (1)
Sub CreatePDF
Dim session As New NotesSession Dim db As NotesDatabase Dim collection As NotesDocumentCollection Dim doc As NotesDocument Dim view As NotesView
Dim JobID As Long Dim PDFFilesName As String
Set db = session.CurrentDatabase Set collection = db.UnprocessedDocuments
JobID = N2PDFInit ( 0 ) ' (2)
If ( JobID >= 0 ) Then ' (3)
Call N2PDFSetOption ( JobID,_ N2PDFOPTION_SYSTEM_LAUNCH_VIEWER,"1","") ' (4)
Call N2PDFAddContent ( JobID, _ ' (6) N2PDFVALUE_CONTENT_HEADER, _ N2PDFVALUE_HF_FIRST_PAGE, _ "Plain text header" )
Call N2PDFAddVariable ( JobID, 0, "CITY", "FULDA" ) ' (7)
Set doc = collection.GetFirstDocument ' (5)
While ( Not ( doc Is Nothing ) ) ' (5)
Call N2PDFAddRTContent ( JobID, _ ' (8) N2PDFVALUE_CONTENT_BODY, _ N2PDFVALUE_PAGEBREAK_AFTER,_ db.Server, _ db.FilePath, _ doc.UniversalID, _ "Lettercontent")
Set doc = collection.GetNextDocument ( doc ) ' (5) Wend ' (5)
PDFFilesName = "C:\Temp\MyPdf.PDF" ' (10)
Call N2PDFProcess ( JobID, PDFFilesName, 0 ) ' (9)
End If
End Sub |