2.3.03. PDF Conversion on the Web

Important notice

Swing PDF Converter does not support "Pass-Thru HTML" content on Lotus forms.
Rendering those forms to PDF will result in PDF document containing HTML/JavaScript source code.

Alternative form should be used to fix the issue:
  1. Lotus Notes Client version of the content form can be set as alternative form.
  2. New form can be created containing Lotus Notes Client design elements with specific layout for PDF conversion.
More on alternative forms here and here.

Installation instructions

To preview the product's web functionality, all you have to do is to follow these few simple steps:
  1. Copy SWING PDF Converter database (PDFConverter.nsf) to your server.
  2. Open Domino Administrator, navigate to PDFConverter.nsf and sign the application with Active Server's ID.
    Sign the database with server's ID

  3. Open PDFConverter.nsf in Lotus Notes and enter your serial key.
  4. In Application properties (5th tab) set "When opened in browser: Open designated Frameset" -> "Frameset: MainWeb".
    Select designated frameset for the web

  5. Open the application in your web browser and click the Create PDF button.
    Web fax form

  6. PDF Converter will now extract all required files. Please restart your Domino server to complete installation.

  7. You should be able to use PDF Converter on the web now
    Resulting PDF document

How it works?

Swing PDF Converter web example UI form is stored in Swing PDF Converter database, in "FaxWeb" form.
Back end code is in the "FaxWeb" agent.

Here's a brief explanation how web conversion works:

- Form "FaxWeb" is a Notes form that is optimized for web display.

- When user clicks on the button "Create PDF", simple formula code that saves the document and closes window is executed: 

- There is an event trigger defined which executes when the document is being saved ("WebQuerySave" event):
  This event executes LotusScript agent "FaxWeb".

- Agent "FaxWeb" initializes Swing PDF Converter, converts the document and constructs output HTML from PDF document path.
  This HTML code is printed to the clients browser.

Sample code

Here's the "FaxWeb" agent source code:
Option Public
Option Declare
Use "SwPDFMain"
Sub Initialize
    Dim s As New NotesSession, docContext As NotesDocument
    Dim swPDF As New SwPDFCreator, swPDFDoc As SwPDFDocument, pdfErr As SwPDFError
    Dim rtitem As NotesRichTextItem, PDFFileName As String, HrefUrl As String
    PDFFileName = "test.pdf"
    Set docContext = s.DocumentContext
    If Not docContext Is Nothing Then
            ' Set alternate form and default file name used for PDF conversion
	    swPDF.PDFSettings.AlternateForm = "Fax"
	    swPDF.PDFSettings.IncludeWebAttachments = True
	    swPDF.FileName = PDFFileName
	    ' enable font embedding for non ascii characters
	    swPDF.PDFSettings.EnableFontEmbedding = True
	    'enable console logging
	    swPDF.PDFSettings.ConsoleLogging = True
	    ' Convert doc to PDF
	    Set swPDFDoc = swPDF.ProcessDocument(docContext)
	    If Not swPDFDoc Is Nothing Then
		' Finally, get generated PDF as RTItem and store it in document for further reference
		Set rtitem = swPDFDoc.GetAsRTItem()
	    	Call rtitem.CopyItemToDocument(docContext, "")
		Call docContext.Save(True, True)
		Call swPDFDoc.Recycle()
		' Construst a URL and display generated PDF in a web browser
		HrefUrl = "0/" & Cstr(docContext.UniversalID) & "/$File/" & PDFFileName
		Print |<span style="font-family: Arial, Helvetica, sans-serif;font-weight: bold;font-size: xx-small;">You can download a copy of PDF file from <a href="| & HrefUrl  & |" >here</a><span><br> | & Chr$(13) & |<embed src="| & hrefUrl & |" width="900px" height = "750px" ></embed>|
		' There was an error in PDF conversion
		Set pdfErr = swPDF.GetError()
		Print "<html><body><p>ERROR: " & pdfErr.Message & "</p></body></html>"
	    End If
	    ' There was an error in PDF initialization
	    Set pdfErr = swPDF.GetError()
	    Print "<html><body><p>ERROR: " & pdfErr.Message & "</p></body></html>"
        End If
    End If
End Sub