convert
conversion
pdf
Tobias Krais (www.design-to-use.de)
How to convert a document in an other format?
import {%see com.sun.star.lang.XComponent};
import {%see com.sun.star.beans.PropertyValue};
import {%see com.sun.star.frame.XStorable};
import {%see com.sun.star.io.IOException};
import {%see com.sun.star.uno.UnoRuntime};
/**
* This method converts documents to other formats.
* See http://www.openoffice.org/files/documents/25/3042/filter_list_ooo_2_0.html
*
* @param targetFilename Name of the file, which is the target of the export.
* @param conversionFilter Contains the conversion filter (see link above).
*/
public void convert(String targetFilename, String conversionFilter)
{
// How to get the XComponent, see {%internal ../Office/Office.OpenDocumentFromURL.snip}
XStorable xStorable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, this.xComponent);
// Set properties for conversions
PropertyValue[] conversionProperties = new PropertyValue[2];
conversionProperties[0] = new PropertyValue();
conversionProperties[0].Name = "Overwrite";
conversionProperties[0].Value = new Boolean(true);
conversionProperties[1] = new PropertyValue();
conversionProperties[1].Name = "FilterName";
conversionProperties[1].Value = conversionFilter;
// Convert
try {
// See {%internal ../Office/Office.CreateUNOCompatibleURL.snip} for method createUNOFileURL(targetFilename);
xStorable.storeToURL(createUNOFileURL(targetFilename),
conversionProperties);
} catch (IOException e) {
e.printStackTrace();
}
}
Linked other methods from the snippet base and thus simplified the method