Custom header and footer is added to PDF document by providing document UNID that holds header and footer data to Swing PDF Converter.
Swing PDF Converter opens this document and looks for fields "SwHeaderBody" and "SwFooterBody".
Swing PDF Converter API package provides form "SwHeaderFooter" with embedded fields "SwHeaderBody" and "SwFooterBody".
Document with custom header/footer data can be created using this form and its UNID provided to Swing PDF Converter.
Alternatively, fields "SwHeaderBody" and "SwFooterBody" can be added to existing database form or appended to document that will be converted. UNID of document that holds header/footer fields must be provided to Swing PDF Converter through PDFSettings:
Use "SwPDFMain"
Option Public
Option Declare
Sub Initialize()
Dim w As New NotesUIWorkspace, doc As NotesDocument, hfDoc As NotesDocument
Dim swPDF As New SwPDFCreator, swPDFDoc As SwPDFDocument, pdfErr As SwPDFError
Dim hfItem As NotesRichTextItem
Dim DestFilePath As Variant
Dim db As NotesDatabase
Dim dialogRes As string
On Error GoTo Ooops
If w.CurrentDocument.IsNewDoc Then
MsgBox "Document must be saved first in order to convert it to a PDF.", 0+48, "WARNING"
Else
' Get destination file path
DestFilePath = w.SaveFileDialog(False, "Save document", "PDF Files (*.pdf)|*.pdf", "", "test.pdf")
If Not IsEmpty(DestFilePath)Then
If Dir$(DestFilePath(0)) <> "" Then
dialogRes = MessageBox(DestFilePath(0) & " already exists." & Chr$(13) & Chr$(10) & "Do you want to replace it?", 4, "Save document")
If dialogRes = 7 Then
Exit Sub
Else
Kill DestFilePath(0)
End If
End If
' Procceed with PDF conversion
' Get currently opened Notes document
Set doc = w.CurrentDocument.Document
Set db = w.Currentdatabase.Database
'===========================================================
' HEADER/FOOTER SECTION
'===========================================================
'Create new header/footer document
Set hfDoc = db.Createdocument()
hfDoc.Form = "SwHeaderFooter"
'Create header RTF
Set hfItem = hfDoc.Createrichtextitem("SwHeaderBody")
'Add header value
hfItem.Appendtext("Header Test")
Set hfItem = Nothing
'Footer RTF
Set hfItem = hfDoc.Createrichtextitem("SwFooterBody")
'Footer value
hfitem.Appendtext("Footer Test")
Set hfItem = Nothing
'Add fields to enable H/F
Set item = hfDoc.Replaceitemvalue("HFEnable", "1")
Set item = Nothing
Set item = hfDoc.Replaceitemvalue("HFDef", "1")
Set item = Nothing
Call hfDoc.Save(false, false, false)
'============================================================
' Initialize PDF creation process; license key is required
If swPDF.Init("<LICENCE KEY GOES HERE>") Then
swPDF.PDFSettings.IncludeAttachments = True
'Apply header/footer doc to Swing PDF Converter
swPDF.PDFSettings.HeaderFooterDocUNID = hfDoc.Universalid
' Convert doc to PDF
Set swPDFDoc = swPDF.ProcessDocument(doc)
If Not swPDFDoc Is Nothing Then
' Finally, save generated PDF to a file on disk
Call swPDFDoc.SaveToFile(DestFilePath(0))
MsgBox "PDF successfully created in " & DestFilePath(0)
Else
' There was an error in PDF conversion
Set pdfErr = swPDF.GetError()
MsgBox pdfErr.Message, 0+16, "ERROR"
End If
Else
' There was an error in PDF initialization
Set pdfErr = swPDF.GetError()
MsgBox pdfErr.Message, 0+16, "ERROR"
End If
'Remove H/F document after conversion
If Not hfDoc Is Nothing Then
Call hfDoc.Remove(true)
End If
End If
End If
Exit Sub
Ooops:
MsgBox "Error " & Error & " On line " & Erl
Exit Sub
End Sub
Note: If you're instead looking for information on how to manage headers and footers in the PDF Converter user interface, please read the following article: