How to set custom PDF settings from LotusScript

Create instance of SwPDFSettings class: Dim pdfSettings As New SwPDFSettings

Then, set values that suites your needs. For example: pdfSettings.MarginLeft = 5

Finally, apply settings to SwPDFCreator class: Set swPDF.PDFSettings = pdfSettings

Here is the full code example that can be used in form action on any form:

Option Declare
Use "SwPDFMain"

Sub Click(Source As Button)
    Dim w As New NotesUIWorkspace, doc As NotesDocument
    Dim swPDF As New SwPDFCreator, swPDFDoc As SwPDFDocument, pdfErr As SwPDFError, pdfSettings As New SwPDFSettings, DestFilePath As Variant

    On Error Goto ErrorHandler

    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

            'Get currently opened Notes document
             Set doc = w.CurrentDocument.Document

            'Initialize PDF creation process; license key is required
            If swPDF.Init("<ADD YOUR LICENCE HERE>") Then

                pdfSettings.MarginLeft = 5
                'Add all settings here
                Set swPDF.PDFSettings = pdfSettings
        
                '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

         End If

    End If

    Exit Sub

    ErrorHandler:
        Msgbox "Error " + Error + " -> " + Erl
        Exit Sub
End Sub

List of available settings in the SwPDFSettings class:

Last updated

Was this helpful?