I am trying to create a individual pdf for every sheet in spreadsheet (except the first two) and name the pdf the same as the name of the sheet (sheet names can contain spaces).
So far I have come up with the following (based on a lot of googleing):
Sub ExportAsPDFs
dim document, oFolderDialog as object
dim pdfDirectory as string
dim i, iExec as integer
oFolderDialog = CreateUnoService("com.sun.star.ui.dialogs.OfficeFolderPicker")
iExec = oFolderDialog.Execute
if iExec = 1 then
pdfDirectory = oFolderDialog.Directory + "/"
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
names() = ThisComponent.Sheets.getElementNames()
for i = 2 to ubound(names)
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file://" + pdfDirectory + join(split(names(i), " "), "") + ".pdf"
args1(1).Name = "FilterName"
args1(1).Value = "calc_pdf_Export"
args1(2).Name = "PageRange"
args1(2).Value = i + 1
dispatcher.executeDispatch(document, ".uno:ExportDirectToPDF", "", 0, args1())
next i
endif
End Sub
This mostly seems to work, except for the last cucial line. I suspect I am doing something wrong somewhere, but am not sure what or where. The error I get is:
Error saving the document <document name>:
General Error.
General input/output error.
Any help would be greatly appreciated.