I have following code to export a sheet to a PDF file:
Option Explicit
Sub exportToPdf
Dim document As Object
Dim dispatcher As Object
document=ThisComponent.CurrentController.Frame
dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
Dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///home/someuser/Desktop/exported.pdf"
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"
dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
End Sub
It is working properly. I have following questions:
Is it possible to export a PDF without creating unoService? (And how to do it?)
How to export a range of cells instead of the whole sheet?
The creating of uno services are not the problem. But the dispatcher you should avoid. Thats why recording a macro with openoffice is not very helpful. You have to bothering yourself with the API.
This tutorial shows how PDF export works in general: https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export
For the customizing a
MediaDescriptor
is needed. https://www.openoffice.org/api/docs/common/ref/com/sun/star/document/MediaDescriptor.htmlThis service may be represented by a ::com::sun::star::beans::PropertyValue[]. This type has
Name
andValue
properties.This
MediaDescriptor
needs at least aFilterName
. A not very actual list of FilterNames can be found here: https://wiki.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0For further customizing a
FilterData
is possible. For those read: https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export#General_propertiesAs of the Filter data demo in https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export#Filter_data_demo for the
Value
of theFilterData
also a array ofPropertyValue
s is used.So we get: