Bugzilla – Attachment 154091 Details for
Bug 127489
Simple ODT with image saved to PDF adds blank page - only via Java API code, normal PDF export works
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Java code to reproduce the problem.
BlankPageProblem.java (text/plain), 4.58 KB, created by
Paul
on 2019-09-11 06:36:37 UTC
(
hide
)
Description:
Java code to reproduce the problem.
Filename:
MIME Type:
Creator:
Paul
Created:
2019-09-11 06:36:37 UTC
Size:
4.58 KB
patch
obsolete
>import java.io.File; >import java.util.concurrent.atomic.AtomicLong; > >import com.sun.star.beans.PropertyValue; >import com.sun.star.frame.XComponentLoader; >import com.sun.star.frame.XDesktop; >import com.sun.star.frame.XModel; >import com.sun.star.frame.XStorable; >import com.sun.star.lang.XComponent; >import com.sun.star.lang.XMultiComponentFactory; >import com.sun.star.uno.UnoRuntime; >import com.sun.star.uno.XComponentContext; >import com.sun.star.util.XCloseable; > > >public class BlankPageProblem >{ > > public static void main(String[] args) throws Exception > { > final File odt = new File("blank-page-problem.odt"); > > Object desktop = null; > try { > XComponentContext mxRemoteContext = bootstrap(); > XMultiComponentFactory mxRemoteServiceManager = getRemoteServiceManager(mxRemoteContext); > desktop = mxRemoteServiceManager.createInstanceWithContext( > "com.sun.star.frame.Desktop", mxRemoteContext); > > // first run sets the expected output file size. > final AtomicLong expectedSize = new AtomicLong(0); > > // try to create 100 PDFs > for(int i=0; i<1000; i++) { > File outputFile = new File("extra-page" + i + ".pdf"); > loadAndSaveAsPdf(odt, outputFile, expectedSize, desktop); > } > > } finally { > if (desktop != null) { > try { > ((XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop)).terminate(); > } catch(Exception e) { > System.err.println("terminate failed"); > e.printStackTrace(); > } > } > } > > } > > private static void loadAndSaveAsPdf(File sourceFile, > File outputFile, AtomicLong expectedSize, Object desktop) > throws Exception > { > > StringBuffer sLoadFileUrl = new StringBuffer("file:///"); > sLoadFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); > > XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); > PropertyValue[] loadProps = new PropertyValue[1]; > loadProps[0] = new PropertyValue(); > loadProps[0].Name = "Hidden"; > loadProps[0].Value = Boolean.TRUE; > > XComponent xDoc = xComponentLoader.loadComponentFromURL( > sLoadFileUrl.toString(), "_blank", 0, loadProps); > > if ( xDoc != null ) { > try { > StringBuffer sStoreFileUrl = new StringBuffer(); > sStoreFileUrl.append(outputFile.toURI().toURL().toString()); > storeDocComponent(xDoc, sStoreFileUrl.toString()); > > if (expectedSize.get() == 0) { > expectedSize.set(outputFile.length()); > System.out.println("Expected output size based on first document:" + expectedSize.get()); > } else if (outputFile.length() != expectedSize.get()) { > throw new RuntimeException("Output File changed size:" + outputFile.length() + > " expected " + expectedSize.get() + " file:" + outputFile.getPath()); > } > } finally { > close(xDoc); > } > } > > } > > > protected static void storeDocComponent(XComponent xDoc, String storeUrl) > throws java.lang.Exception > { > > XStorable xStorable = UnoRuntime.queryInterface(XStorable.class, xDoc); > PropertyValue[] storeProps = new PropertyValue[1]; > storeProps[0] = new PropertyValue(); > storeProps[0].Name = "FilterName"; > storeProps[0].Value = "writer_pdf_Export"; > > System.out.println("... store to \"" + storeUrl > + "\"."); > xStorable.storeToURL(storeUrl, storeProps); > } > > private static void close(XComponent doc) throws Exception > { > XModel xModel = (com.sun.star.frame.XModel) UnoRuntime > .queryInterface(com.sun.star.frame.XModel.class, doc); > > XCloseable xCloseable = (com.sun.star.util.XCloseable) UnoRuntime > .queryInterface(com.sun.star.util.XCloseable.class, xModel); > > if (xCloseable != null) { > try { > xCloseable.close(false); > } catch (com.sun.star.util.CloseVetoException e) { > System.err.println("Document close was vetoed"); > } > } > else { > XComponent xDisposeable = (com.sun.star.lang.XComponent) UnoRuntime > .queryInterface(com.sun.star.lang.XComponent.class, > xModel); > xDisposeable.dispose(); > } > } > > private static XComponentContext bootstrap() throws Exception > { > XComponentContext mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); > return mxRemoteContext; > } > > private static XMultiComponentFactory getRemoteServiceManager(XComponentContext mxRemoteContext) > throws java.lang.Exception > { > > System.out.println("Connected to a running office ..."); > return mxRemoteContext.getServiceManager(); > } > > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 127489
:
154090
| 154091 |
154092
|
154093
|
158665