Hi,
once again, i have a question:
i've searched in different forums but didn't find a good solution:
the task is: export a template.ott to pdf via commandline
1.: Is there an easy way doing this without a macro?
2.: Is it possible to run a macro on a template from commandline?
3.: where is the syntax documentation for using macros from the commandline?
thanks again
quietschie
[Solved] Export a template.ott to pdf via commandline
-
- Posts: 6
- Joined: Tue May 04, 2010 4:00 pm
[Solved] Export a template.ott to pdf via commandline
Last edited by Hagar Delest on Thu May 06, 2010 11:16 am, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice.org 3.2 on Windows Vista
-
- Posts: 6
- Joined: Tue May 04, 2010 4:00 pm
Re: export a template.ott to pdf via commandline
Hi evryone,
I solved the problem by using a macro with a fixed specified outputfile and a parameter with the inputfile:
the commandline call is the following:
two things are worth to be mentioned:
the -headless option only works, when the macro is in the "Meine Makros" or respectively "My Makros" Library because only this library is loaded by default
in order to access the "Meine Makros" folder, you just have to leave out the document name in the path "macro://document/Standard..." turns to "macro:///Standard..."
The macro itself is postet below:
to find this out cost me about one day and 4 hours...please feel free to save time and use it.
quietschie
I solved the problem by using a macro with a fixed specified outputfile and a parameter with the inputfile:
the commandline call is the following:
Code: Select all
soffice.exe -headless "macro:///Standard.Module1.printPdf(D:\inputfile.ott)"
the -headless option only works, when the macro is in the "Meine Makros" or respectively "My Makros" Library because only this library is loaded by default
in order to access the "Meine Makros" folder, you just have to leave out the document name in the path "macro://document/Standard..." turns to "macro:///Standard..."
The macro itself is postet below:
Code: Select all
sub printPdf(cFile as string)
dim dispatcher as object
cURL = ConvertToURL( cFile )
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///D:/Benutzerprofile/kauppdl/workspace2/karawasa/bon/actual.pdf"
args1(1).Name = "FilterName"
args1(1).Value = "writer_pdf_Export"
args2(0).Name = "Hidden"
args2(0).Value = True
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, args2())
dispatcher.executeDispatch(oDoc.getCurrentController, ".uno:ExportDirectToPDF", "", 0, args1())
end sub
quietschie
OpenOffice.org 3.2 on Windows Vista
Re: [Solved] Export a template.ott to pdf via commandline
Thanks for sharing, this could be useful to others.
Ubuntu 14.10 Utopic Unicorn, LibreOffice Version: 4.3.3.2
Gurkha Welfare Trust
Gurkha Welfare Trust
Re: [Solved] Export a template.ott to pdf via commandline
I can't seem to run this macro - I changed "
args1(0).Value = "file:///D:/Benutzerprofile/kauppdl/workspace2/karawasa/bon/actual.pdf"" to
args1(0).Value = "file:///D:/actual.pdf" and then tried to run it using the command "C:\Program Files (x86)\OpenOffice.org 3\program>soffice.exe "macro:///Standard.
odule1.printPDF(D:\testfile.odf)"" but I get the error:
BASIC Runtime Error
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: URL seems to be an unsupported one..
At line:
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, args2())
Am I doing something wrong, or is cURL supposed to be replaced with something else? I'm using a Windows system.
args1(0).Value = "file:///D:/Benutzerprofile/kauppdl/workspace2/karawasa/bon/actual.pdf"" to
args1(0).Value = "file:///D:/actual.pdf" and then tried to run it using the command "C:\Program Files (x86)\OpenOffice.org 3\program>soffice.exe "macro:///Standard.
odule1.printPDF(D:\testfile.odf)"" but I get the error:
BASIC Runtime Error
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: URL seems to be an unsupported one..
At line:
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, args2())
Am I doing something wrong, or is cURL supposed to be replaced with something else? I'm using a Windows system.
OpenOffice.org 3.2.1 OOO320m18
Windows 7 Ultimate x64
Intel Core i3 530 @ 2.93 GHz
4 GB RAM
Windows 7 Ultimate x64
Intel Core i3 530 @ 2.93 GHz
4 GB RAM
Re: [Solved] Export a template.ott to pdf via commandline
I solved this using some cobbled together and some original code. This is how I set up the macro to take the .doc file and export it as .PDF, including keeping the original name based on the parameter used for the file path.
Command Line Call: C:\>"C:\Program Files (x86)\OpenOffice.org 3\program\soffice.exe" "macro:///Standard.Module1.printPDF(D:\My Product\Data\Product User's Manual.doc)"
This code takes the parameter of the full path used of the original file and produces a PDF in the same directory with the same name. If anyone sees this and cringes (I'm an amateur programmer, if you can even count this as programming) code critique is much appreciated.
-Isarian
Command Line Call: C:\>"C:\Program Files (x86)\OpenOffice.org 3\program\soffice.exe" "macro:///Standard.Module1.printPDF(D:\My Product\Data\Product User's Manual.doc)"
Code: Select all
sub printPdf(cFile as string)
dim dispatcher as object
cURL = ConvertToURL( cFile )
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
cFile = Replace( cFile, "\", "/" )
nPosExtension = InStr( cFile, "." )
cFile = Mid$( cFile, 1, nPosExtension - 1 )
args1(0).Name = "URL"
args1(0).Value = "file:///" + cFile + ".pdf"
args1(1).Name = "FilterName"
args1(1).Value = "writer_pdf_Export"
args2(0).Name = "Hidden"
args2(0).Value = True
oDoc = StarDesktop.loadComponentFromURL(cURL, "_blank", 0, args2())
dispatcher.executeDispatch(oDoc.getCurrentController, ".uno:ExportDirectToPDF", "", 0, args1())
-Isarian
OpenOffice.org 3.2.1 OOO320m18
Windows 7 Ultimate x64
Intel Core i3 530 @ 2.93 GHz
4 GB RAM
Windows 7 Ultimate x64
Intel Core i3 530 @ 2.93 GHz
4 GB RAM