[Java example] Pdf export with filter data

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Java example] Pdf export with filter data

Postby hol.sten » Fri Jan 18, 2008 9:19 pm

This post is based on the Bootstrap Connection Mechanism and shows a Java example of how to add several PDF export settings like PDF security, page range, image quality, and settings for the PDF viewer for a PDF export:
Code: Select all   Expand viewCollapse view
package oootest;

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public class DocumentToPdfWithFilterData {
    public static void main(String[] args) {
        String loadUrl="file:///c:/dev/netbeans/oootest/mydoc.odt";
        String storeUrl="file:///c:/dev/netbeans/oootest/mydoc.pdf";

        try {
            XComponentContext xContext = Bootstrap.bootstrap();
            XMultiComponentFactory xMultiComponentFactory = xContext.getServiceManager();
            XComponentLoader xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,xMultiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));

            Object objectDocumentToStore = xcomponentloader.loadComponentFromURL(loadUrl, "_blank", 0, new PropertyValue[0]);

            // Create PDF filter data
            PropertyValue pdfFilterData[] = new PropertyValue[19];

            // Filter data comments origin:
            // http://www.openoffice.org/nonav/issues/showattachment.cgi/37895/draft-doc-pdf-security.odt
            // http://specs.openoffice.org/appwide/pdf_export/PDFExportDialog.odt

            // Set the password that a user will need to change the permissions
            // of the exported PDF. The password should be in clear text.
            // Must be used with the “RestrictPermissions” property
            pdfFilterData[0] = new PropertyValue();
            pdfFilterData[0].Name = "PermissionPassword";
            pdfFilterData[0].Value = "nopermission";

            // Specify that PDF related permissions of this file must be
            // restricted. It is meaningfull only if the “PermissionPassword”
            // property is not empty
            pdfFilterData[1] = new PropertyValue();
            pdfFilterData[1].Name = "RestrictPermissions";
            pdfFilterData[1].Value = new Boolean(true);

            // Set the password you must know to open the PDF document
            pdfFilterData[2] = new PropertyValue();
            pdfFilterData[2].Name = "DocumentOpenPassword";
            pdfFilterData[2].Value = "open";

            // Specifies that the PDF document should be encrypted while
            // exporting it, meanifull only if the “DocumentOpenPassword”
            // property is not empty
            pdfFilterData[3] = new PropertyValue();
            pdfFilterData[3].Name = "EncryptFile";
            pdfFilterData[3].Value = new Boolean(true);

            // Specifies printing of the document:
            //   0: PDF document cannot be printed
            //   1: PDF document can be printed at low resolution only
            //   2: PDF document can be printed at maximum resolution.
            pdfFilterData[4] = new PropertyValue();
            pdfFilterData[4].Name = "Printing";
            pdfFilterData[4].Value = new Integer(0);

            // Specifies the changes allowed to the document:
            //   0: PDF document cannot be changed
            //   1: Inserting, deleting and rotating pages is allowed
            //   2: Filling of form field is allowed
            //   3: Filling of form field and commenting is allowed
            //   4: All the changes of the previous selections are permitted,
            //      with the only exclusion of page extraction
            pdfFilterData[5] = new PropertyValue();
            pdfFilterData[5].Name = "Changes";
            pdfFilterData[5].Value = new Integer(4);

            // Specifies that the pages and the PDF document content can be
            // extracted to be used in other documents: Copy from the PDF
            // document and paste eleswhere
            pdfFilterData[6] = new PropertyValue();
            pdfFilterData[6].Name = "EnableCopyingOfContent";
            pdfFilterData[6].Value = new Boolean(false);

            // Specifies that the PDF document content can be extracted to
            // be used in accessibility applications
            pdfFilterData[7] = new PropertyValue();
            pdfFilterData[7].Name = "EnableTextAccessForAccessibilityTools";
            pdfFilterData[7].Value = new Boolean(false);
           
            // Specifies which pages are exported to the PDF document.
            // To export a range of pages, use the format 3-6.
            // To export single pages, use the format 7;9;11.
            // Specify a combination of page ranges and single pages
            // by using a format like 2-4;6.
            // If the document has less pages than defined in the range,
            // the result might be the exception
            // "com.sun.star.task.ErrorCodeIOException".
            // This exception occured for example by using an ODT file with
            // only one page and a page range of "2-4;6;8-10". Changing the
            // page range to "1" prevented this exception.
            // For no apparent reason the exception didn't occure by using
            // an ODT file with two pages and a page range of "2-4;6;8-10".
            pdfFilterData[8] = new PropertyValue();
            pdfFilterData[8].Name = "PageRange";
            pdfFilterData[8].Value = "2-4;6;8-10";
            // pdfFilterData[8].Value = "1";
           
            // Specifies if graphics are exported to PDF using a
            // lossless compression. If this property is set to true,
            // it overwrites the "Quality" property
            pdfFilterData[9] = new PropertyValue();
            pdfFilterData[9].Name = "UseLosslessCompression";
            pdfFilterData[9].Value = new Boolean(true);
           
            // Specifies the quality of the JPG export in a range from 0 to 100.
            // A higher value results in higher quality and file size.
            // This property affects the PDF document only, if the property
            // "UseLosslessCompression" is false
            pdfFilterData[10] = new PropertyValue();
            pdfFilterData[10].Name = "Quality";
            pdfFilterData[10].Value = new Integer(50);

            // Specifies if the resolution of each image is reduced to the
            // resolution specified by the property "MaxImageResolution".
            // If the property "ReduceImageResolution" is set to true and
            // the property "MaxImageResolution" is set to a DPI value, the
            // exported PDF document is affected by this settings even if
            // the property "UseLosslessCompression" is set to true, too
            pdfFilterData[11] = new PropertyValue();
            pdfFilterData[11].Name = "ReduceImageResolution";
            pdfFilterData[11].Value = new Boolean(true);
           
            // If the property "ReduceImageResolution" is set to true
            // all images will be reduced to the given value in DPI
            pdfFilterData[12] = new PropertyValue();
            pdfFilterData[12].Name = "MaxImageResolution";
            pdfFilterData[12].Value = new Integer(100);

            // Specifies whether form fields are exported as widgets or
            // only their fixed print representation is exported
            pdfFilterData[13] = new PropertyValue();
            pdfFilterData[13].Name = "ExportFormFields";
            pdfFilterData[13].Value = new Boolean(false);

            // Specifies that the PDF viewer window is centered to the
            // screen when the PDF document is opened
            pdfFilterData[14] = new PropertyValue();
            pdfFilterData[14].Name = "CenterWindow";
            pdfFilterData[14].Value = new Boolean(true);

            // Specifies the action to be performed when the PDF document
            // is opened:
            //   0: Opens with default zoom magnification
            //   1: Opens magnified to fit the entire page within the window
            //   2: Opens magnified to fit the entire page width within
            //      the window
            //   3: Opens magnified to fit the entire width of its boundig
            //      box within the window (cuts out margins)
            //   4: Opens with a zoom level given in the “Zoom” property
            pdfFilterData[15] = new PropertyValue();
            pdfFilterData[15].Name = "Magnification";
            pdfFilterData[15].Value = new Integer(4);

            // Specifies the zoom level a PDF document is opened with.
            // Only valid if the property "Magnification" is set to 4
            pdfFilterData[16] = new PropertyValue();
            pdfFilterData[16].Name = "Zoom";
            pdfFilterData[16].Value = new Integer(120);

            // Specifies that automatically inserted empty pages are
            // suppressed. This option only applies for storing Writer
            // documents.
            pdfFilterData[17] = new PropertyValue();
            pdfFilterData[17].Name = "IsSkipEmptyPages";
            pdfFilterData[17].Value = new Boolean(true);

            // Specifies the PDF version that should be generated:
            //   0: PDF 1.4 (default selection)
            //   1: PDF/A-1 (ISO 19005-1:2005)
            pdfFilterData[18] = new PropertyValue();
            pdfFilterData[18].Name = "SelectPdfVersion";
            pdfFilterData[18].Value = new Integer(1);


            PropertyValue[] conversionProperties = new PropertyValue[3];
            conversionProperties[0] = new PropertyValue();
            conversionProperties[0].Name = "FilterName";
            conversionProperties[0].Value = "writer_pdf_Export";
            conversionProperties[1] = new PropertyValue();
            conversionProperties[1].Name = "Overwrite ";
            conversionProperties[1].Value = new Boolean(true);
            conversionProperties[2] = new PropertyValue();
            conversionProperties[2].Name = "FilterData";
            conversionProperties[2].Value = pdfFilterData;

            XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class,objectDocumentToStore);
            xstorable.storeToURL(storeUrl,conversionProperties);
        }
        catch (java.lang.Exception e) {
            e.printStackTrace();
        }
        finally {
            System.exit(0);
        }
    }   
}

Most of the settings work on there own without affecting other settings. But some of them affect other. So if a setting does not work as expected, take a closer look at the comments.

I don't think that it is useful to use all of the above settings at once. I only wanted to demonstrate how to set several PDF settings. And there are still more. So if you miss a setting, read the documents I used to get most parts of the filter data comments in the above example:
- http://www.openoffice.org/nonav/issues/ ... curity.odt
- http://specs.openoffice.org/appwide/pdf ... Dialog.odt
- http://wiki.services.openoffice.org/wik ... PDF_export
I got the link to both documents from this post: http://www.mail-archive.com/dev@api.ope ... 03726.html
Last edited by hol.sten on Sun Mar 28, 2010 5:54 pm, edited 4 times in total.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Change log

Postby hol.sten » Fri Jan 18, 2008 9:25 pm

28. Mar 2010: Added PropertyValue() "SelectPdfVersion"
10. Feb 2008: Added PropertyValue() "IsSkipEmptyPages"
18. Jan 2008: Creation of the Java example
03. Feb 2008: Comment for "PageRange" extended (explanation of "com.sun.star.task.ErrorCodeIOException" and how to prevent it)
Last edited by hol.sten on Sun Mar 28, 2010 5:49 pm, edited 1 time in total.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby briglia23 » Wed Feb 11, 2009 10:31 am

Hi all.

I have this code to convert a odt to pdf with java. I use java 1.5 and OOo 2.3

Code: Select all   Expand viewCollapse view
public PDFDocument() {
      
      oooBundle = com.yacme.docoutput.DocOutput.oooBundle;
      if (oooBundle == null) {
         oooBundle = ResourceBundle.getBundle("OOo");
      }
      if (ooohost == null) {
         ooohost = oooBundle.getString("ooohost");
      }
      if (oooport == null) {
         oooport = new Integer(oooBundle.getString("oooport"));
      }


      saveProperties = new PropertyValue[3];
      saveProperties[0] = new PropertyValue();
      saveProperties[0].Name = "FilterName";
      saveProperties[0].Value = "writer_pdf_Export";
      saveProperties[1] = new PropertyValue();
      saveProperties[1].Name = "Overwrite";
      saveProperties[1].Value = "TRUE";
      saveProperties[2] = new PropertyValue();
      saveProperties[2].Name = "CompressionMode";
      saveProperties[2].Value = "1";
    
      if (openProperties == null) {
         openProperties = new PropertyValue[2];

         openProperties[0] = new PropertyValue();
         openProperties[0].Name = "Hidden";
         openProperties[0].Value = new Boolean(true);

         openProperties[1] = new PropertyValue();
         openProperties[1].Name = "AsTemplate";
         openProperties[1].Value = new Boolean(false);
      }


Code: Select all   Expand viewCollapse view
public void saveDocument(String type) throws OOoException {
      XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
      String document = normalizeFileURL(this.docPath + java.io.File.separator + this.docName.replaceFirst("odt$", type));
      System.out.println("Salvo il documento " + document + " ...");
      try {
         xStorable.storeToURL(document, saveProperties);
      } catch (IOException e) {
         e.printStackTrace();
         throw new OOoException("Impossibile esportare il documento in PDF. " + e.getMessage());
      }

   }


It's doesn't run i get this Exception:

Code: Select all   Expand viewCollapse view
com.sun.star.task.ErrorCodeIOException:
        at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:187)
        at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:153)
        at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:349)
        at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:318)
        at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:106)
        at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:657)
        at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:159)
        at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:141)
        at $Proxy7.storeAsURL(Unknown Source)
        at com.yacme.builder.PDFDocument.saveDocument(PDFDocument.java:111)
        at com.yacme.commersald.CommersaldManager.run(CommersaldManager.java:262)
        at java.lang.Thread.run(Thread.java:595)
com.yacme.exceptions.OOoException: Impossibile esportare il documento in PDF.
        at com.yacme.builder.PDFDocument.saveDocument(PDFDocument.java:114)
        at com.yacme.commersald.CommersaldManager.run(CommersaldManager.java:262)
        at java.lang.Thread.run(Thread.java:595)



i start OOo fron openoffice2.3/program with this command:
Code: Select all   Expand viewCollapse view
./soffice -nocrashreport -norestore -headless -display :2 "-accept=socket,port=8100,host=0;urp"


Can you help me?

Thanks
OOo 2.3.X on openSuse 10
briglia23
 
Posts: 155
Joined: Tue Jun 24, 2008 10:09 am

Re: [Java example] Pdf export with filter data

Postby hol.sten » Thu Feb 12, 2009 11:19 pm

briglia23 wrote:
Code: Select all   Expand viewCollapse view
saveProperties[1].Name = "Overwrite";
saveProperties[1].Value = "TRUE";

"TRUE" is a string. You need here new Boolean(true) instead.

briglia23 wrote:
Code: Select all   Expand viewCollapse view
saveProperties[2].Name = "CompressionMode";
saveProperties[2].Value = "1";

What is this? Where did you get this from? It's useless. Drop it. Take a closer look at my first post in the thread for adding compression to your properties.

briglia23 wrote:Can you help me?

Why don't you help yourself? Start with a piece of working code like the one I posted in this thread. Get it working. And start then modifying it to your needs. Doing it that way will lead you much faster to success.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby ashish_1234 » Fri Jul 10, 2009 7:47 am

hi

i am able to convert a word document into pdf using the above code...

i want to convert a whole document into PDF without using page ranges properties.

so please give me any suggestion how can i achive this using your ciode.

Second thing i want to know is when i will run this code a openoffice window is opening ..

at run time i dont want to see this window in my application how can i avoid this.,

if you can help me in this it will be a great help from you.

Thanks for the nice code.
OOo 2.3.X on Ms Windows XP
ashish_1234
 
Posts: 3
Joined: Wed Jul 08, 2009 8:25 am

Re: [Java example] Pdf export with filter data

Postby calorie » Thu Aug 20, 2009 3:41 am

Hi
Thanks for your example.
I tried this example, it works. But when it runs, the program opens Oo writer, it seems loadComponentFromURL method will open a frame to load the doucument then do the export. This is not I want, I want to use JAVA API to write a convertor program separatly, is that possiable?
In other words, JAVA API just supports a way to invoke the sub-programs of local OpenOffice program, is that so?
OpenOffice on Windows 3.1
calorie
 
Posts: 6
Joined: Thu Aug 20, 2009 3:28 am

Re: [Java example] Pdf export with filter data

Postby hol.sten » Thu Aug 20, 2009 10:52 pm

calorie wrote:In other words, JAVA API just supports a way to invoke the sub-programs of local OpenOffice program, is that so?

You always need a running OOo server. All you can do is to suppress the OOo Writer window by using the -headless parameter. The -headless parameter has been discussed a lot in OOo forums. Read more on this here for example:
- viewtopic.php?f=16&t=1549&p=7986&hilit=headless
- http://blogs.linux.ie/caolan/2007/05/04/headless-ooo/
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby groverblue » Tue Sep 01, 2009 7:21 pm

Is there still no option for color mode (ie, the ability to save in grayscale)?

Also, here is a page I found in the wiki talks about the PDF export filters:

http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export
groverblue
 
Posts: 40
Joined: Wed Mar 26, 2008 6:17 pm

Re: [Java example] Pdf export with filter data

Postby hol.sten » Tue Sep 01, 2009 7:37 pm

groverblue wrote:Is there still no option for color mode (ie, the ability to save in grayscale)?

None that I've heard of.

groverblue wrote:Also, here is a page I found in the wiki talks about the PDF export filters:
http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export

Thanks for the link!
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby groverblue » Tue Sep 01, 2009 9:30 pm

Which version of the API do these setting apply? It's so hard to find documentation for the API.
groverblue
 
Posts: 40
Joined: Wed Mar 26, 2008 6:17 pm

Re: [Java example] Pdf export with filter data

Postby hol.sten » Tue Sep 01, 2009 10:12 pm

groverblue wrote:Which version of the API do these setting apply?

At least OOo 2.x.x. But my guess is that the example works with OOo 3.x.x, too. Although I didn't give it a try yet.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby groverblue » Wed Sep 02, 2009 7:38 pm

I'm unable to reduce the size of my PDF files. Below is code and comparison sizes. BTW, I'm testing with OOo 2.4.1.

Without any filter data information:

Code: Select all   Expand viewCollapse view
PropertyValue[] storeProps = new PropertyValue[3];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "writer_pdf_Export";

storeProps[1] = new PropertyValue();
storeProps[1].Name = "Pages";
storeProps[1].Value = "All";

storeProps[2] = new PropertyValue();
storeProps[2].Name = "Overwrite";
storeProps[2].Value = Boolean.TRUE;


With compression:

Code: Select all   Expand viewCollapse view
PropertyValue[] filterData = new PropertyValue[5];

filterData[0] = new PropertyValue();
filterData[0].Name = "UseLosslessCompression";
filterData[0].Value = Boolean.FALSE;

filterData[1] = new PropertyValue();
filterData[1].Name = "Quality";
filterData[1].Value = new Integer(50);

filterData[2] = new PropertyValue();
filterData[2].Name = "ReduceImageResolution";
filterData[2].Value = Boolean.TRUE;

filterData[3] = new PropertyValue();
filterData[3].Name = "MaxImageResolution";
filterData[3].Value = new Integer(150);

filterData[4] = new PropertyValue();
filterData[4].Name = "ExportFormFields";
filterData[4].Value = Boolean.FALSE;

PropertyValue[] storeProps = new PropertyValue[4];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "writer_pdf_Export";

storeProps[1] = new PropertyValue();
storeProps[1].Name = "Pages";
storeProps[1].Value = "All";

storeProps[2] = new PropertyValue();
storeProps[2].Name = "Overwrite";
storeProps[2].Value = Boolean.TRUE;

storeProps[3] = new PropertyValue();
storeProps[3].Name = "FilterData";
storeProps[3].Value = filterData;

FileManager.componentExport(xc, storeProps, filePath);


Code: Select all   Expand viewCollapse view
File #   Compressed (bytes)   Uncompressed (bytes)
1          73,639               71,807
2          67,858               66,726
3          56,849               56,849
4          66,551               65,994
5          71,648               71,648
6          60,724               60,724
7          53,569               53,162
8          63,805               63,805
9          61,136               61,136
10         56,550               56,550
11         57,676               57,676
12         66,222               66,222
13         71,423               71,104
14         60,393               60,393
15         59,455               58,786
16         65,497               65,497
17         61,422               61,422
Total:     1,074,417            1,014,221


As you can see, my files are about the same. What's more striking is the fact that my uncompressed size totals best their compressed versions by 60,196 bytes. So, I'm better without compression.
All these files are single page, with the exception of three files which are 2 pages. As a comparison, I have a PDF from Apple (the Objective-C language) that is 133 pages, but only weighs in at 1,185,911 bytes.

There are 3 types of PDFs with embedded fonts:

Code: Select all   Expand viewCollapse view
#1
CourierNewPSMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in
TimesNewRomanPS-ItalicMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in
TimesNewRomanPSMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in

#2
Symbol
   Type: Type1
   Encoding: Built-in
   Actual Font: Symbol
   Actual Font Type: Type 1
TimesNewRomanPS-BoldMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in
TimesNewRomanPSMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in

#3
TimesNewRomanPS-BoldMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in
TimesNewRomanPSMT (Embedded Subset)
   Type: TrueType
   Encoding: Built-in


Below are my files and their type:
File #   Type
1       1
2       2
3       3
4       3
5       3
6       3
7       3
8       3
9       3
10      2
11      2
12      2
13      2
14      2
15      2
16      2
17      3


Any thoughts?
groverblue
 
Posts: 40
Joined: Wed Mar 26, 2008 6:17 pm

Re: [Java example] Pdf export with filter data

Postby hol.sten » Wed Sep 02, 2009 10:47 pm

groverblue wrote:As you can see, my files are about the same.

Are you using pictures in your documents? If not, all the filter data you added was in vain! All your extra filter data only reduces the file size of a PDF if your documents contains pictures.

You cannot reduce the files size of PDF text documents created by OOo through adding filter data. OOo always embedds the used fonts of a document into the PDF. Which fonts are you using? The only possibility to prevent font embedding is to use standard PDF fonts like Helvatica (not Arial), Courier (not CourierNew) or Times (not TimeNewRoman).

BTW: What has your last question in common with you previous question regarding an option for color mode?
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby groverblue » Wed Sep 02, 2009 10:59 pm

groverblue
 
Posts: 40
Joined: Wed Mar 26, 2008 6:17 pm

Re: [Java example] Pdf export with filter data

Postby groverblue » Wed Sep 02, 2009 11:05 pm

hol.sten wrote:Are you using pictures in your documents? If not, all the filter data you added was in vain! All your extra filter data only reduces the file size of a PDF if your documents contains pictures.

You cannot reduce the files size of PDF text documents created by OOo through adding filter data. OOo always embedds the used fonts of a document into the PDF. Which fonts are you using? The only possibility to prevent font embedding is to use standard PDF fonts like Helvatica (not Arial), Courier (not CourierNew) or Times (not TimeNewRoman).

BTW: What has your last question in common with you previous question regarding an option for color mode?


I just added details about my fonts to the previous post. About half the files have images; some header images, other signature images, but nothing too drastic. My question about grayscale was really related to file size. I was hoping that having the ability to generated b&w PDFs would result in a smaller file.

I guess the problem with must be with embedded fonts, but I have a document from Apple that is 133 pages, with 7 embedded fonts, and it's only 1.1Mb. I can list the font if you want.

One more thing: how do you know that OOo behaves the way you say regarding font types? Is there documentation available on which font can be used without having them embedded in a PDF?

 Edit: I just did a test with a file. Changing Times New Roman to Times results in an 85% reduction in size (56,849 to 8,417). Wow. Thank you. I just need to determine all the font types that can be safely used. 
groverblue
 
Posts: 40
Joined: Wed Mar 26, 2008 6:17 pm

Re: [Java example] Pdf export with filter data

Postby hol.sten » Thu Sep 03, 2009 7:53 pm

groverblue wrote:I just need to determine all the font types that can be safely used.

I listed all I know in my previous post. And I know them from reading various posts in several OOo forums and from trying them for myself.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby mytam » Fri Nov 20, 2009 6:49 pm

Hello,
I noticed you using the FilterData for PDF export. Do you know how to export the PDF in grayscale? I don't see any filtering options that allow me to do so. Please help.

Thanks,
tam
mytam
 
Posts: 3
Joined: Thu Oct 08, 2009 6:02 pm

Re: [Java example] Pdf export with filter data

Postby hol.sten » Fri Nov 20, 2009 10:38 pm

mytam wrote:Do you know how to export the PDF in grayscale? I don't see any filtering options that allow me to do so.

There is no such setting.
OOo 3.2.0 on Ubuntu 10.04 • OOo 3.2.1 on Windows 7 64-bit and MS Windows XP
hol.sten
Volunteer
 
Posts: 495
Joined: Mon Oct 08, 2007 1:31 am
Location: Hamburg, Germany

Re: [Java example] Pdf export with filter data

Postby swesten » Thu Aug 18, 2011 11:00 pm

This might come in handy if you want to export a single sheet:
(in my case each sheets contains an invoice that I want to export separately as pdf)

public void convert2Pdf(XSpreadsheetDocument xSpreadsheetDocument, String outputFolder, String sheetName) {
try {
PropertyValue pdfFilterData[] = new PropertyValue[2];
pdfFilterData[0] = new PropertyValue();
pdfFilterData[0].Name = "Selection";
XSpreadsheets spreadsheets = xSpreadsheetDocument.getSheets();
try {
pdfFilterData[0].Value = select(xSpreadsheetDocument, getSheet(spreadsheets, sheetName));
} catch (Exception e) {
throw new IllegalStateException("unexpected exception during invoice generation - pdf part", e);
}
// Specifies the changes allowed to the document:
// 0: PDF document cannot be changed
pdfFilterData[1] = new PropertyValue();
pdfFilterData[1].Name = "Changes";
pdfFilterData[1].Value = 0;

PropertyValue[] lProperties = new PropertyValue[3];
lProperties[0] = new PropertyValue();
lProperties[0].Name = "FilterName";
lProperties[0].Value = "calc_pdf_Export";
lProperties[1] = new PropertyValue();
lProperties[1].Name = "Overwrite";
lProperties[1].Value = true;

lProperties[2] = new PropertyValue();
lProperties[2].Name = "FilterData";
lProperties[2].Value = pdfFilterData;

XFileIdentifierConverter fileContentProvider = openOfficeConnection.getFileContentProvider();
String outputUrl = fileContentProvider.getFileURLFromSystemPath("", new File(outputFolder).getAbsolutePath() + "/invoice " + sheetName + ".pdf");
XStorable xStore = UnoRuntime.queryInterface(XStorable.class, xSpreadsheetDocument);

xStore.storeToURL(outputUrl,lProperties);
} catch (com.sun.star.io.IOException e) {
throw new IllegalStateException("unexpected exception", e);
}
}


private Object select(XInterface xInterface, Object aAny){
Object oSelection = null;
try {
XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xInterface);
if (xModel != null){
XController xController = xModel.getCurrentController();
XSelectionSupplier xSelectionSupplier = (XSelectionSupplier) UnoRuntime.queryInterface(
XSelectionSupplier.class, xController);
xSelectionSupplier.select(aAny);
// there is really no need to retrieve the selection
oSelection = xSelectionSupplier.getSelection();
}
} finally {
return oSelection;
}
}
OpenOffice 3.1 on Ubuntu 10.0
swesten
 
Posts: 2
Joined: Thu Aug 18, 2011 10:20 pm

Re: [Java example] Pdf export with filter data

Postby zmotiwala » Mon Feb 27, 2012 9:08 pm

Can an existing pdf file be converted to a PDF/A document using Open office 3.0.

If so how?

Could I get some sample code?
Libre Office 5.2.5
Windows
zmotiwala
 
Posts: 41
Joined: Wed Dec 28, 2011 5:34 pm

Re: [Java example] Pdf export with filter data

Postby Villeroy » Mon Feb 27, 2012 9:26 pm

OOo is not a PDF editor. PDF is just another way of printing.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Java example] Pdf export with filter data

Postby RoryOF » Mon Feb 27, 2012 9:28 pm

zmotiwala wrote:Can an existing pdf file be converted to a PDF/A document using Open office 3.0.
If so how?
Could I get some sample code?


You have to use other tools for this, such as discussed at
http://stackoverflow.com/questions/1659147/how-to-use-ghostscript-to-convert-pdf-to-pdf-a-or-pdf-x
Apache OpenOffice 4.1.7 on Xubuntu 20.04.1 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31416
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Java example] Pdf export with filter data

Postby hanya » Mon Feb 27, 2012 10:27 pm

Can an existing pdf file be converted to a PDF/A document using Open office 3.0.
If you have a plan to convert existing pdf file into PDF/A-1a, it is very difficult task. Because of most of pdf files are lost logical structure of the original document and they have not tag for their structures anymore.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Java example] Pdf export with filter data

Postby zmotiwala » Tue Apr 10, 2012 6:32 pm

Is there any way to set keywords for a PDF file using PropertyValues?
Libre Office 5.2.5
Windows
zmotiwala
 
Posts: 41
Joined: Wed Dec 28, 2011 5:34 pm

Re: [Java example] Pdf export with filter data

Postby hanya » Tue Apr 10, 2012 6:56 pm

zmotiwala wrote:Is there any way to set keywords for a PDF file using PropertyValues?
No way with it but File - Properties, Description - Keywords is set to the /Keywords information entries of the PDF.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Java example] Pdf export with filter data

Postby zmotiwala » Mon Apr 23, 2012 5:05 pm

Code: Select all   Expand viewCollapse view
XDocumentPropertiesSupplier xProps = OfficeUtils.cast(XDocumentPropertiesSupplier.class, document);
            if(xProps != null) {
                XDocumentProperties props = xProps.getDocumentProperties();
                if(props != null) {
                    String[] keywordArr = new String[keywords.size()];
                    int i = 0;
                    for(String key : keywords.keySet()) {
                        keywordArr[i++] = key + " : " + keywords.get(key);
                    }
                    props.setKeywords(keywordArr);
                }
            }


Cast the XDocument as a the XDocumentPropertiesSupplier and set the keywords.
Libre Office 5.2.5
Windows
zmotiwala
 
Posts: 41
Joined: Wed Dec 28, 2011 5:34 pm


Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests