Symphony Thursday: Developer 201 - Saving & Generating PDF’s

May 7 2009




Symphony Thursday: Developer 101

1. Introduction to UNO Development and Documents/Writer "Hello World"
2. Spreadsheets"Hello World"
3. Presentations "Hello World"

Last time, I covered the basics of UNO Development and walked you thru a "Hello World" application for OpenOffice.org Writer and Lotus Symphony Presentations. This blog entry will cover how any file type - documents, spreadsheets, or presentations, can be saved as a PDF.

How Lotus Symphony Saves


Lotus Symphony and OpenOffice.org have a built in command that save the current file. If we take the Lotus Symphony Presentations document we generated in the Presentations: "Hello World", we would do the following to save the file

     Call Presentation.storeToURL("file:///C:/symphonythursdaypresentation.odp", args)

The storeToURL method has two parameters. The first is the complete path of where you want to save the presentation. Just as when we were creating the presentation, we have to use a URL format for the filepath. The reference to "file:///" tells Symphony to save to the local file system. You could use other url commands here such as "ftp://" to save to a FTP site on an internet server. The rest of the path is the location on the hard drive, the file name, and the file extension. Just remember to do "C:/" instead of "C:\" - this is not normal or UNC pathing.

The second parameter is variant that must be passed in. When just saving to standard document formats, you will not have any values in this variant. You can define the args variant with the following code

    Dim args() As Variant

Saving PDFs

Saving a presentation as a PDF in Lotus Symphony requires a bit more code, but the process is the same.

     Call Presentation.storeToURL("file:///C:/symphonythursdaypresentation.pdf", argsPDF)

We are using the same method to save the PDF, but the second parameter is different. We are now going to set values for the argsPDF variant.

     Dim args1 As Variant
     Dim args2 As Variant
     Set args1= SM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
     Set args2= SM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")

The first thing we need to do is create two variants and set them to the Structure of PropertyValue. Just like we did before, we are using the Service Manager (SM) and calling the Bridge_GetStruct method. The parameter we are passing is a registered object that sets the variants to a JavaBean within Lotus Symphony called PropertyValue. Remember the rule - much of this is overcomplicated, so please enjoy the fact the hard work has been done for you!
       
     args1.Name = "URL"
     args1.Value = "file:///C:/symphonythursdaypresentation.pdf"
     args2.Name = "FilterName"
     args2.Value = "writer_pdf_Export"

Next, we set the PropertyValue variants. Each property value has two properties: Name and Value. The first property is called Name and the second is Value. As you can see, we set a Property called "URL" with the full file path and a second called "FilterName" that gets a special value that tells Symphony and OpenOffice.org which export filter to use.
       
     Dim argsPDF(1) As Variant
     Set argsPDF(0)=args1
     Set argsPDF(1)=args2

The last step is to set our final variant as we did when saving the presentation normally, but this time it is a 2 dimensional array. We set in the args1 and args2 PropertyValue variants.

The Results


Image:Symphony Thursday: Developer 201 - Saving & Generating PDF’s
The presentation saved as an ODF (odp) and PDF file



Conclusion


To try this yourself, create a new button in a Notes document in Notes 8.0.1, 8.0.2, or 8.5. 8.0.0 will not work as it does not properly register the components in the registry. With 8.0.0 or Notes 6, 6.5, or 7.X, you can use this code with OpenOffice.org 1.1.6 or higher, 2.x, or 3.x. Try it and see it work for yourself:

Dim SM As Variant
Dim Desktop As Variant
Dim ImpressApplication As Variant
Dim Presentation As Variant
Dim Slide As Variant
Dim Title As Variant
Dim TitleText As Variant
Dim Cursor As Variant
Dim args()
Dim args1 as Variant
Dim args2 as Variant
Dim argsPDF(1) as Variant
     
Set SM=CreateObject("com.sun.star.ServiceManager")
Set Desktop=SM.createInstance("com.sun.star.frame.Desktop")
Set ImpressApplication=Desktop.loadComponentFromURL("private:factory/simpress","_blank",0,args)
Set Presentation=ImpressApplication.getDrawPages()
Set Slide=Presentation.getByIndex(0)
Slide.layout=1'this layout has a title and an outline
Set title=Slide.getbyindex(0)'the first shape is the title        
Set TitleText=title.getText()'this bit is like talking to writer
Set Cursor=TitleText.createTextCursor()
Call TitleText.insertString(Cursor,"Hello World!",False)

Call Presentation.storeToURL("file:///C:/symphonythursdaypresentation.odp", args)

Set args1= SM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
Set args2= SM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
args1.Name = "URL"
args1.Value = "file:///C:/symphonythursdaypresentation.pdf"
args2.Name = "FilterName"
args2.Value = "writer_pdf_Export"

Set argsPDF(0)=args1
Set argsPDF(1)=args2

Call Presentation.storeToURL("file:///C:/symphonythursdaypresentation.pdf", argsPDF)


Next time, we will look at working with bookmarks in Lotus Symphony Documents / Writer.


0 Responses to “Symphony Thursday: Developer 201 - Saving & Generating PDF’s”

    No Comments Found

Leave a Reply