OO-Snippets: Store any as *.pdf

Commons

Keywordspdf
LanguageooRexx
ApplicationWriter
AuthorsMatthias Prem (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow can I store any text document as *.pdf?
Answer

Code-Snippet-Listing (snippet-source)

/* StoreAnyAsPDF.rex */
/* run from command line */
/* parts of this script are taken from A. Ahammer */

/* connect to server and get the service manager */
xContext = UNO.connect()
XMcf = xContext~getServiceManager

/* get the desktop and XComponentLoader */
xDesktop         = UNO.createDesktop(xContext)
xComponentLoader = xDesktop~XDesktop~XComponentLoader

/* loading an existing document */
loadprops = bsf.createArray(.UNO~propertyValue, 1)
loadprops[1] = .UNO~PropertyValue~new
loadprops[1]~Name  = "Visible"
loadprops[1]~Value = box("boolean", .true)
xWriterComponent = xComponentLoader~loadComponentFromURL("file:///C:/text.odt", "_blank", 0, loadprops)

/* storing the document as pdf */
xStorable = xWriterComponent~XStorable
storeprops = bsf.createArray(.UNO~propertyValue, 2)
storeprops[1] = .UNO~PropertyValue~new
storeprops[1]~Name  = "FilterName"
storeprops[1]~Value = "writer_pdf_Export"
storeprops[2] = .UNO~PropertyValue~new
storeprops[2]~Name  = "CompressMode"
storeprops[2]~Value = 2
xStorable~storeToUrl("file:///C:/text.pdf", storeprops)

/* close the Writer */
xWriterComponent~dispose()

::requires UNO.CLS

Changelog

DateUserModification
2006-07-10matthiaspremInitial version

and