public void storeToURL( /*IN*/ String aURL, /*IN*/ com.sun.star.beans.PropertyValue[] aArguments ) throws com.sun.star.io.IOException { xStorable.storeToURL( aURL, aArguments ); }
String storeUrl = "file:///C:/Users/JimStandard/Desktop/Test.odt"; XStorable xStorable = (XStorable) UnoRuntime.queryInterface( XStorable.class, xTextDocument); PropertyValue[] storeProps = new PropertyValue[1]; storeProps[0] = new PropertyValue(); storeProps[0].Name = "Overwrite"; storeProps[0].Value = new Boolean(true); try { xStorable.storeToURL(storeUrl, storeProps); } catch (com.sun.star.io.IOException ex) { ex.printStackTrace(System.err); System.exit(1); } try { URL url = new URL(storeUrl); // this is Path testPath = Paths.get(url.toURI()); byte[] data = Files.readAllBytes(testPath); System.out.println("Length = " + data.length); } catch (java.io.IOException ex) { ex.printStackTrace(System.err); System.exit(1); } catch (URISyntaxException ex) { ex.printStackTrace(System.err); System.exit(1); }
public void saveXComponent(XComponent xComponent, XOutputStream xOutputStream, String filterName) throws IOException { PropertyValue[] props = new PropertyValue[2]; props[0] = new PropertyValue(); props[1] = new PropertyValue(); props[0].Name = "OutputStream"; props[0].Value = xOutputStream; props[1].Name = "FilterName"; props[1].Value = filterName; XStorable xStorable = as(XStorable.class, xComponent); xStorable.storeToURL("private:stream", props); }
public void saveXComponent(XComponent xComponent, XOutputStream xOutputStream, String filterName) throws IOException { PropertyValue[] props = new PropertyValue[2]; props[0] = new PropertyValue(); props[1] = new PropertyValue(); props[0].Name = "OutputStream"; props[0].Value = xOutputStream; props[1].Name = "FilterName"; props[1].Value = filterName; XStorable xStorable = as(XStorable.class, xComponent); xStorable.storeToURL("private:stream", props); }
private void storeDocument(XComponent document, File outputFile) throws OfficeException { Map<String,?> storeProperties = getStoreProperties(outputFile, document); if (storeProperties == null) { throw new OfficeException("unsupported conversion"); } try { cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties)); } catch (ErrorCodeIOException errorCodeIOException) { throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException); } catch (IOException ioException) { throw new OfficeException("could not store document: " + outputFile.getName(), ioException); } }
private void storeDocument(XComponent document, File outputFile) throws OfficeException { Map<String,?> storeProperties = getStoreProperties(outputFile, document); if (storeProperties == null) { throw new OfficeException("unsupported conversion"); } try { cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties)); } catch (ErrorCodeIOException errorCodeIOException) { throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException); } catch (IOException ioException) { throw new OfficeException("could not store document: " + outputFile.getName(), ioException); } }
private void storeDocument(XComponent document, File outputFile) throws OfficeException { Map<String,?> storeProperties = getStoreProperties(outputFile, document); if (storeProperties == null) { throw new OfficeException("unsupported conversion"); } try { cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties)); } catch (ErrorCodeIOException errorCodeIOException) { throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException); } catch (IOException ioException) { throw new OfficeException("could not store document: " + outputFile.getName(), ioException); } }
System.out.println("starting..."); String oooExeFolder = "/usr/lib/openoffice/program"; XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder); XMultiComponentFactory xMCF = xContext.getServiceManager(); Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); XComponentLoader xCLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); System.out.println("loading "); PropertyValue[] printerDesc = new PropertyValue[1]; printerDesc[0] = new PropertyValue(); printerDesc[0].Name = "PaperOrientation"; printerDesc[0].Value = PaperOrientation.LANDSCAPE; // Create a document XComponent document = xCLoader.loadComponentFromURL(loadUrl, "_blank", 0, printerDesc); // Following property will convert doc into requested orientation. XPrintable xPrintable = (XPrintable) UnoRuntime.queryInterface(XPrintable.class, document); xPrintable.setPrinter(printerDesc); PropertyValue[] conversionProperties = new PropertyValue[3]; conversionProperties[1] = new PropertyValue(); conversionProperties[1].Name = "FilterName"; conversionProperties[1].Value = "writer_pdf_Export";// conversionProperties[0] = new PropertyValue(); conversionProperties[0].Name = "Overwrite "; conversionProperties[0].Value = new Boolean(true); System.out.println("closing"); XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); xstorable.storeToURL(storeUrl, conversionProperties); System.out.println("closing"); XCloseable xcloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document); xcloseable.close(false);
private void loadAndExport(InputStream inputStream, Map/*<String,Object>*/ importOptions, OutputStream outputStream, Map/*<String,Object>*/ exportOptions) throws Exception { XComponentLoader desktop = openOfficeConnection.getDesktop(); Map/*<String,Object>*/ loadProperties = new HashMap(); loadProperties.putAll(getDefaultLoadProperties()); loadProperties.putAll(importOptions); // doesn't work using InputStreamToXInputStreamAdapter; probably because it's not XSeekable //property("InputStream", new InputStreamToXInputStreamAdapter(inputStream)) loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); XComponent document = desktop.loadComponentFromURL("private:stream", "_blank", 0, toPropertyValues(loadProperties)); if (document == null) { throw new OpenOfficeException("conversion failed: input document is null after loading"); } refreshDocument(document); Map/*<String,Object>*/ storeProperties = new HashMap(); storeProperties.putAll(exportOptions); storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); try { XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); storable.storeToURL("private:stream", toPropertyValues(storeProperties)); } finally { document.dispose(); } } }
private void storeDocument(XComponent document, String outputUrl, Map storeProperties) throws com.sun.star.io.IOException { try { XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); storable.storeToURL(outputUrl, toPropertyValues(storeProperties)); } finally { XCloseable closeable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document); if (closeable != null) { try { closeable.close(true); } catch (CloseVetoException closeVetoException) { logger.warn("document.close() vetoed"); } } else { document.dispose(); } } }