Hi
I recently made an application and needed a way in C# to open an .odt
file and convert to and pdf file before opening open office, I managed
to find a way but after upgrading to 3.0 this doesn't work anymore.
In my visual studio project I reference 4 dll's; cli_basetypes.dll,
cli_cppuhelper, cli_types.dll and cli_ure.dll
Here is the code that worked before:
private static string SaveAsPDF(string filename)
{
try
{
XComponentContext localContext = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory)
localContext.getServiceManager();
XComponentLoader componentLoader =
(XComponentLoader)
multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
//sett the property
PropertyValue[] propertyValue = new PropertyValue[1];
PropertyValue aProperty = new PropertyValue();
aProperty.Name = "Hidden";
aProperty.Value = new uno.Any(true);
propertyValue[0] = aProperty;
XComponent xComponent =
componentLoader.loadComponentFromURL(PathConverter(filename), "_blank",
0, propertyValue);
PropertyValue[] saveProps = new PropertyValue[1];
saveProps[0] = new PropertyValue();
saveProps[0].Name = "FilterName";
saveProps[0].Value = new Any("writer_pdf_Export");
string pdffilename = PathConverter(filename.Replace(".odt", ".pdf"));
((XStorable) xComponent).storeToURL(pdffilename, saveProps);
xComponent.dispose();
return pdffilename;
}
catch(Exception e)
{
throw new ODTException("Could not save the .odt document as
pdf",ExceptionSeverity.Warn, e);
}
}
I found out that openoffice 3 doesn't have the dll's in the installation
folder but instead in th GAC so I copied them from there but that just
resulted in another error:
System.Runtime.InteropServices.SEHException: External component has
thrown an exception.\r\n at
cppu.bootstrap(Reference<com::sun::star::uno::XComponentContext>* )\r\n
at uno.util.Bootstrap.bootstrap()\r\n
I would of course like to come up with a solution that works with new
openoffice releases as well as 3.0. It is not important whether it works
with 2.4.
Can anyone help me?