Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


Hello! This is my first post to this list. 

We have a large number of PDF documents that we need to modify slightly and 
save. After a fair amount of research, it seems like the LibreOffice API and the 
TextReplace.java code sample should get me rather close to the mark. I almost 
have the script working, but I'm having trouble telling libreoffice to open the 
PDF as a PDF rather than a text document. The result is a bunch of 
gobbledygook. 

Here's the file I started with: 
http://api.libreoffice.org/examples/java/Text/TextReplace.java

I'm running on a spare desktop system, Fedora 21, fresh install, all updates 
applied. EG: 
java-1.8.0-openjdk-1.8.0.40-25.b25.fc21.x86_64
libreoffice-core-4.3.6.2-8.fc21.x86_64
libreoffice-writer-4.3.6.2-8.fc21.x86_64

I've successfully modified the script so that it finds and opens the example PDF 
I'm using, which has been provided to have the same text as the 
TextReplace.java example. When it opens the file, it's not importing the PDF, 
instead it's reading it as a text file or something. 

You can see what this looks like here: (I'm not running headless on purpose) 
http://hal.schoolpathways.com/libre/screenshot.png

Looking at the documentation, it looks like there's an "Arguments" parameter 
which reads: 

"Arguments    these arguments specify component or filter specific behavior

For example, "ReadOnly" with a boolean value specifies whether the document
is opened read-only. "FilterName" specifies the component type to create
and the filter to use, for example: "Text - CSV". For more information see
com::sun::star::document::MediaDescriptor."

See 
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1frame_1_1XComponentLoader.html

This leads to TypeDetection but I have not figured out how to find out what 
"FilterName" I should use to specify that I'm importing a PDF. 

Below is the code fragment that I'm using now. My *guess* is that this line is 
the culprit: 

        loadProps[0].Value = "X-Application/PDF";

but I can't be sure. I'm guessing the following references are related, but 
nowhere am I seeing a *list* of import filters that I can use, nor a way to find 
out what filters are available in my install. 

http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/ImportFilter.html
http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/FilterFactory.html

Applicable snippet below, the full .java script that I'm using is visible 
http://hal.schoolpathways.com/libre/TextReplace.java


---- SNIP ------
// ORIGINAL EXAMPLE
//        String sURL = "private:factory/" + sDocumentType;

// SEES PDF AS A TEXT DOCUMENT.
//      String sURL = "file:///home/ben/pdf/example.pdf";
        String sURL = "file:///home/ben/pdf/example.pdf";


        com.sun.star.lang.XComponent xComponent = null;
        com.sun.star.frame.XComponentLoader xComponentLoader = null;
//        com.sun.star.beans.PropertyValue xEmptyArgs[] =
//            new com.sun.star.beans.PropertyValue[0];

        com.sun.star.beans.PropertyValue[] loadProps =
            new com.sun.star.beans.PropertyValue[3];

        loadProps[0] = new         com.sun.star.beans.PropertyValue();
        loadProps[0].Name = "FilterData";
        loadProps[0].Value = "X-Application/PDF";

        try {
            xComponentLoader = UnoRuntime.queryInterface(
                com.sun.star.frame.XComponentLoader.class, xDesktop);

            xComponent  = xComponentLoader.loadComponentFromURL(
                sURL, "_blank", 0, loadProps);
        }
---- SNIP ------


Your time and attention are much appreciated. 

Benjamin Smith 

-- 
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.