Sample program

 

The following script shows the use of the PDF export filter in NotesToPaper and LotusScript respectively. The script is incomplete and thus not run-enabled as-is. A complete script may be found in the sample application NTPPDF.NSF, which is copied to the client's Notes data directory during installation, and can be found using the icon in the program group. The database contains an "ExportAsPDF" script library, which in turn contains the complete routine.

 

Note: All comments are shown in italics and all important commands in the script are highlighted in bold typeface.

 

First the report is activated ...

 

ReportID = NTPInitFromDatabase ( "CONLIST", ServerName, DatabaseName, NTPPROCESS_SHOWMESSAGES )

 

If ReportID >= 0 Then                      

 

Important: After activating the report, it is important to prevent the report from being deleted after having been processed by NTPProcessReportExt!!!

Status = NTPSetOption ( ReportID, NTPOPTION_KEEPREPORT, 1 )

 

Show no preview

Status = NTPSetOption ( ReportID, NTPOPTION_SHOWPREVIEWWINDOW, 0 )

 

Cycle through all documents in the database        

Set doc = view.GetFirstDocument

 

While ( Not ( doc Is Nothing ) )

 

Pass all fields to the report (by document)

Call NTPSendFieldByName ( ReportID, "COMPANYNAME", Cstr(doc.CompanyName(0) ) )

….

….

                 

Close a dataset for the report

Status = NTPEndDocument ( ReportID )

 

Set doc = view.GetNextDocument ( doc )

 

Wend

 

End data transfer

Status = NTPEnd ( ReportID )

 

Important: Report execution and output must be made to the preview!

Status = NTPProcessReportExt ( ReportID, _

         NTPPROCESS_PRINTTOSCREEN, _

         NTPPROCESS_HIDEPRINTERDIALOG, _

         NTPPROCESS_SHOWSTATUSBAR, _

         NTPPROCESS_SHOWMESSAGES, 0 )

         

Has the report been created?        

If ( Status = 0 ) Then

 

After successfully creating the report, the report name can be is accessible. It is important to do this for security purposes. This name is also needed in order to delete the preview file at a later point in time.

The report ID, not the file name, is passed when exporting the report at a later stage.

 

StrBuffer = Space(254)

 

Status = NTPGetReportFileName ( ReportID, StrBuffer )

StrBuffer = Trim ( StrBuffer )

                 

Is there a valid preview file?                

If ( StrBuffer <> "" ) Then

 

The NTPCreateTempFile function allows the creation of a file to generate the report. The file created must have the extension .pdf.

tmpFileName = Trim$ ( NTPCreateTempFile ( "PDF" ) )

 

Has the temp file been created?                        

If ( tmpFileName <> "" ) Then

                                 

Define options for PDF export                                

PDFOptions = _

NTPEXPORT_PDF_FONT_USE_TRUETYPE + _

NTPEXPORT_PDF_COMPRESSION + _

NTPEXPORT_PDF_LAUNCH_APPLICATION

 

The function NTPExport is used to open the export filter and create the PDF file.

Status = NTPExportReport ( ReportID, 0, 6, tmpFileName, 1, 1, PDFOptions, "", "","" )

 

If ( Status <> 0 ) Then

Messagebox ( "NotesToPaper Error: " + NTPGetErrorText ( Status ) )

Else

Messagebox ( "The report was created as a PDF file." & Chr(13) & Chr (10) & "If the PDF viewer does not start automatic, the PDF can be viewed by opening the following file: " & tmpFileName )

End If

                                 

End If

 

The preview file created earlier has to be deleted once the export is completed! Normally NotesToPaper® automatically deletes the preview file, but since this was deactivated in our script, the file will have to be manually deleted in this case.

 

Kill ( StrBuffer )

End If

                 

End If

         

End If