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:

PDFSettingsUNID
    String. Read/write. Universal ID of the document containing PDF settings (must be created with ".PDFSettings" form).
    If set, it automatically overrides all the other corresponding SwPDFSettings options.

PageHeight
    Double. Read/write. Page height in inches; defaults to 11in.

PageWidth
    Double. Read/write. Page width in inches; defaults to 8.5in.

MarginTop
    Double. Read/write. Margin top in inches; defaults to 1in.

MarginLeft
    Double. Read/write. Margin left in inches; defaults to 0in.

MarginBottom
    Double. Read/write. Margin bottom in inches; defaults to 1in.

MarginRight
    Double. Read/write. Margin right in inches; defaults to 0.5in.

AlternateForm
    String. Read/write. Name of the alternate form that will be used for PDF conversion instead of the form documents
    has been created with.

AlternateFormsCol
    Variant. Read/write. Multi-value string list of alternate forms that will be used with document collections. Each
    element in this list should contain actual form name and alias form name, separated with "|" character (e.g. "FormName|AliasFormName").
    If document from collection is created with a form that is contained in this property, corresponding alias form will
    be used instead. If form is not contained within this property, AlternateForm property will then be used (if defined;
    otherwise, original form will be used to create PDF).

IncludeAttachments
    Boolean. Read/write. True, if Notes document attachments needs to be embedded to a resulting PDF file; otherwise False.

AttachmentsOption
    Integer. Read/write. This property will be used only when IncludeAttachments is set to True. Possible values
    are: SWPDF_ATTACH_NATIVE (default), SWPDF_CONVERT_AND_ATTACH, SWPDF_CONVERT_AND_APPEND, SWPDF_ATTACHMENTS_ONLY

IncludeWebAttachments
    Boolean. Read/write. If set to True, PDF document will also contain "web attachments" (attachments that are not associated with any RTF).
    Default is False.

UserPassword
    String. Read/write. Password required to open PDF document.

MasterPassword
    String. Read/write. Password required to change PDF document.

Enable128bitEncryption
    Boolean. Read/write. True, if encryption level needs to be set to 128-bit RC4 (Acrobat 5.x¸ 6.x); defaults to False,
    which is 40-bit RC4 (Acrobat 3.x¸ 4.x) encryption. This property takes effect only when either UserPassword or MasterPassword is set.

EnablePrinting
    Boolean. Read/write. If set to False, PDF document printing will be disabled; default is True. This property takes effect only
    when either UserPassword or MasterPassword is set.

EnableChanging
    Boolean. Read/write. If set to False, modifying PDF document content will be disabled; default is True. This property
    takes effect only when either UserPassword or MasterPassword is set.

EnableCopying
    Boolean. Read/write. If set to False, PDF document copying will be disabled; default is True. This property takes effect only
    when either UserPassword or MasterPassword is set.

EnableComments
    Boolean. Read/write. If set to False, PDF document comments will be disabled; default is True. This property takes effect only
    when either UserPassword or MasterPassword is set.

EnableFormFields
    Boolean. Read/write. If set to False, PDF document form fields will be disabled; default is True. This property takes
    effect only when either UserPassword or MasterPassword is set.

HTMLContainer
    String. Read/write. Name of the field on document that will contain HTML, that needs to be converted to PDF.
    Note that this field should be visible in read mode in order to get PDF with rendered HTML.

EnableFontEmbedding
    Boolean. Default is False. In order to enable font embedding, SystemFontsDir parameter must also be set.

EnableCJKSupport
    Boolean. Set this property to True, if Chinese, Japanese, Korean or Vietnamese characters are used. Default is False.

SystemFontsDir
    String. System folder where fonts are stored (e.g. c:\windows\fonts on Windows OS).

Last updated