Difference between revisions of "API/Tutorials/PDF export"

From Apache OpenOffice Wiki
< API‎ | Tutorials
Jump to: navigation, search
(Modifying the configuration)
(Modifying the configuration)
Line 674: Line 674:
 
             xPropertySet.setPropertyValue("Zoom", new Integer(60));
 
             xPropertySet.setPropertyValue("Zoom", new Integer(60));
 
              
 
              
 +
            //you must commit the changes, if not they will be lost
 
             XChangesBatch xChangesBatch = (XChangesBatch) UnoRuntime.queryInterface(
 
             XChangesBatch xChangesBatch = (XChangesBatch) UnoRuntime.queryInterface(
 
                     XChangesBatch.class, xPropertySet);
 
                     XChangesBatch.class, xPropertySet);

Revision as of 17:51, 7 April 2008

PDF Export filter data

The following tables contain all the properties available in the PDF export filter implementation in OpenOffice.org 2.4.

The tables follow the order of the PDF Export dialog tab pages, so that you can easily understand their meaning just comparing them with this dialog.

Notes:


General properties

Property Name
Description
Type
Default value
PageRange If this property is set, it indicates the range of pages to be printed.

If you want to print all the pages, leave this property unset.

If you want to export a selection, leave this property unset, setting only the property Selection.

string
empty
(all pages are printed)
Selection An any corresponding to the current selection in the document.
any
UseLosslessCompression Specifies if graphics are exported to PDF using a lossless compression eg. PNG or if they are compressed using the JPEG format.
boolean
false
Quality Specifies quality of the JPG export. A higher value results in higher quality and file.

Minimum inclusive value: 1. Represents lowest value that can be used. The lower the value, the less good is the compression quality and the bigger is be the file size.

Minimum inclusive value:100. Represents highest value that can be used. The higher the value, the better is the compression quality and the smaller is the file size.

long
90
ReduceImageResolution Specifies if the resolution of each image is reduced to the resolution specified by the property MaxImageResolution.
boolean
false
MaxImageResolution If the property ReduceImageResolution is set to true all images will be reduced to the given value in DPI.

Posible values:

  • 75
  • 150
  • 300
  • 600
  • 1200


long
300
SelectPdfVersion Specifies the version of PDF to emit.

Possible values:

  • 0 = PDF 1.4 (default selection).
  • 1 = PDF/A-1 (ISO 19005-1:2005)


long
0
UseTaggedPDF Determines if PDF are created by using special tags also known as Tagged PDF.
boolean
false
ExportFormFields Specifies whether form fields are exported as widgets or only their fixed print representation is exported.
boolean
true
FormsType Specifies the submitted format of a PDF form.

Possible values:

  • 0= Specifies that forms type FDF is used.
  • 1= Specifies that forms type PDF is used.
  • 2= Specifies that forms type HTML is used.
  • 3= Specifies that forms type XML is used.


long
0
ExportBookmarks Specifies if bookmarks are exported to PDF.
boolean
true
ExportNotes Specifies if notes are exported to PDF.
boolean
false
ExportNotesPages Specifies if notes pages are exported to PDF. (Notes pages are available in Impress documents only).
boolean
false
IsSkipEmptyPages Specifies that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents.
boolean
false
IsAddStream Specifies that a stream is inserted to the PDF file which contains the original document for archiving purposes.
boolean
false


Initial view

Property Name
Description
Type
Default value
InitialView Specifies how the PDF document should be displayed when opened.

Possible values:

  • 0= Select the default viewer mode, neither outlines or thumbnails.
  • 1= The document is opened with outline pane opened
  • 2= The document is opened with thumbnail pane opened


long
0
InitialPage Specifies the page on which a PDF document should be opened in the viewer application.
long
1
Magnification Specifies the action to be performed when the PDF document is opened.

Possible values:

  • 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 the zoom level specified in the Zoom property.


long
0
Zoom specifies the zoom level a PDF document is opened with. Only valid if "Magnification" is set to "4".
long
100
PageLayout Specifies the page layout to be used when the document is opened.

Possible values:

  • 0= Display the pages according to the reader configuration.
  • 1= Display one page at a time.
  • 2= Display the pages in one column.
  • 3= Display the pages in two columns odd pages on the right, to have the odd pages on the left the FirstPageOnLeft property should be used as well.


long
0
FirstPageOnLeft Used with the value 3 of the PageLayout property above, true if the first page (odd) should be on the left side of the screen.
boolean
false


User interface

Property Name
Description
Type
Default value
ResizeWindowToInitialPage Specifies that the PDF viewer window is opened full screen when the document is opened.
boolean
false
CenterWindow Specifies that the PDF viewer window is centered to the screen when the PDF document is opened.
boolean
false
OpenInFullScreenMode Specifies that the PDF viewer window is opened full screen, on top of all windows.
boolean
false
DisplayPDFDocumentTitle Specifies that the title of the document, if present in the document properties, is displayed in the PDF viewer window title bar.
boolean
true
HideViewerMenubar Specifies whether to hide the PDF viewer menubar when the document is active.
boolean
false
HideViewerToolbar Specifies whether to hide the PDF viewer toolbar when the document is active.
boolean
false
HideViewerWindowControls Specifies whether to hide the PDF viewer controls when the document is active.
boolean
false
UseTransitionEffects Specifies slide transitions are exported to PDF. This option is active only if storing Impress documents.
boolean
true
OpenBookmarkLevels Specifies how many bookmark levels should be opened in the reader application when the PDF gets opened.

Possible values:

  • -1: all bookmark levels are opened
  • 1 – 10: indicate a bookmark level (from 1 to 10)


long
-1


Links

Property Name
Description
Type
Default value
ExportBookmarksToPDFDestination Specifies that the bookmarks contained in the source OpenOffice.org file should be exported to the PDF file as Named Destination (see PDF 1.4 section 8.2.1).
boolean
false
ConvertOOoTargetToPDFTarget Specifies that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched.
boolean
false
ExportLinksRelativeFsys Specifies that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location.
boolean
false
PDFViewSelection Specifies the way the exported PDF will be viewed (experienced) by the user.

Possible values:

  • 0 = Specifies that the PDF will be exported with all the links external to the document treated as URI. This is the Default
  • 1 = Specifies that the PDF will be exported in order to be viewed through a PDF reader application only. Valid only if not exporting to PDF/A-1 (e.g. SelectPdfVersion not set to 1).
  • 2 = Specifies that the PDF will be exported in order to be viewed through an Internet browser, using the PDF plug-in provided with it. The bookmark of the URI will be rendered compatible with the target bookmark generated with OOo PDF Export feature (see ExportBookmarksToPDFDestination, below).


long
0


Security

Property Name
Description
Type
Default value
EncryptFile If true, selects to encrypt the PDF document with a password. The PDF file can be opened only when the user enters the correct password.
boolean
false
DocumentOpenPassword This is the password that allows the user to open the PDF file is "EncryptFile" is set to true.
string
RestrictPermissions If true, selects to restrict some permissions. The permissions can be changed only when the user enters the correct password.
boolean
false
PermissionPassword This is the password that allows the user to access some permissions restricted if "RestrictPermissions" is set to true.
string
Printing Specifies what printing is allowed.

Possible values:

  • 0 = The document cannot be printed.
  • 1 = The document can be printed at low resolution only.
  • 2 = The document can be printed at maximum resolution.


long
2
Changes Specifies the change allowed to the document.

Possible values:

  • 0 = The document cannot be changed.
  • 1 = Inserting deleting and rotating pages is allowed.
  • 2 = Filling of form field is allowed.
  • 3 = Both 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 (copy).


long
4
EnableCopyingOfContent Specifies that the pages and the document content can be extracted to be used in other documents (copy and paste).
boolean
true
EnableTextAccessForAccessibilityTools Specifies that the document content can be extracted to be used in accessibility applications.
boolean
true

PDF Export Configuration

The settings of PDF export dialog are stored in the OpenOffice.org registry every time the this dialog is used and the user confirms his/her choices. Not all properties passed to the PDF filter a are stored in the registry (as it makes no sense to store the page range to be exported, or the passwords for protecting the document).

The following is a list of the properties available in the node path /org.openoffice.Office.Common/Filter/PDF/Export:

  1. CenterWindow
  2. Changes
  3. CompressMode [deprecated]
  4. ConvertOOoTargetToPDFTarget
  5. DisplayPDFDocumentTitle
  6. EnableCopyingOfContent
  7. EnableTextAccessForAccessibilityTools
  8. ExportBookmarks
  9. ExportBookmarksToPDFDestination
  10. ExportFormFields
  11. ExportLinksRelativeFsys
  12. ExportNotes
  13. ExportNotesPages
  14. FirstPageOnLeft
  15. FormsType
  16. HideViewerMenubar
  17. HideViewerToolbar
  18. HideViewerWindowControls
  19. InitialPage
  20. InitialView
  21. IsAddStream
  22. IsSkipEmptyPages
  23. Magnification
  24. MaxImageResolution
  25. OpenBookmarkLevels
  26. OpenInFullScreenMode
  27. PDFViewSelection
  28. PageLayout
  29. Printing
  30. Quality
  31. ReduceImageResolution
  32. ResizeWindowToInitialPage
  33. SelectPdfVersion
  34. UseLosslessCompression
  35. UseTaggedPDF
  36. UseTransitionEffects
  37. Zoom

The following properties are not part of the registry:

  1. DocumentOpenPassword
  2. EncryptFile
  3. PageRange
  4. PermissionPassword
  5. RestrictPermissions
  6. Selection

Accessing the configuration

import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.XPropertySetInfo;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
 
 
public class PDFExportConfigAccess {
 
    private final XComponentContext m_xContext;
 
    public PDFExportConfigAccess(XComponentContext xContext){
        m_xContext = xContext;        
    }
 
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
 
            PDFExportConfigAccess demo = new PDFExportConfigAccess(xContext);
            demo.run();
 
        } catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }
 
    public void run(){
 
        Object oConfig = getPDFConfigAccess(m_xContext);
 
        if (oConfig == null ) {
            System.out.println("Impossible to access the PDF configuration");
            return;
        }
 
        XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(
                XPropertySet.class, oConfig);
 
        XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo();
 
        Property[] properties = xPropertySetInfo.getProperties();
 
        System.out.println("\nProperties and values\n");
 
        for (Property property : properties) {
            String sValue = "";
            try {
                Object aValue = xPropertySet.getPropertyValue( property.Name );
                sValue = String.valueOf( aValue );
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            System.out.println(property.Name + " =\t" + sValue);
        }
    }
 
    public static Object getPDFConfigAccess(XComponentContext xContext){
 
        Object oPDFExportConfig = null;
        try {
 
            XMultiComponentFactory xMCF = xContext.getServiceManager();
 
            Object oConfigProvider = xMCF.createInstanceWithContext(
                    "com.sun.star.configuration.ConfigurationProvider", xContext);
 
            XMultiServiceFactory oConfigProvMSF = 
                    (XMultiServiceFactory) UnoRuntime.queryInterface(
                XMultiServiceFactory.class, oConfigProvider);
 
            PropertyValue[] args = new PropertyValue[1];
 
            args[0] = new PropertyValue();
            args[0].Name = "nodepath";
            args[0].Value = "/org.openoffice.Office.Common/Filter/PDF/Export/";
 
            String sServiceName = "com.sun.star.configuration.ConfigurationAccess";
 
            oPDFExportConfig = oConfigProvMSF.createInstanceWithArguments(
                    sServiceName, args);
 
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return oPDFExportConfig;
        }
    }
 
 
}

Modifying the configuration

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XChangesBatch;
 
 
public class PDFExportConfigUpdate {
 
    private final XComponentContext m_xContext;
 
    public PDFExportConfigUpdate(XComponentContext xContext){
        m_xContext = xContext;        
    }
 
    public static void main(String[] args) {
        try {
            // get the remote office component context
            XComponentContext xContext = Bootstrap.bootstrap();
 
            PDFExportConfigUpdate demo = new PDFExportConfigUpdate(xContext);
            demo.run();
 
        } catch (java.lang.Exception e){
            e.printStackTrace();
        }
        finally {
            System.exit( 0 );
        }
    }
 
    public void run() {
 
 
        Object oConfig = getPDFConfigUpdateAccess(m_xContext);
 
        if (oConfig == null) {
            System.out.println("Impossible to access the PDF configuration");
            return;
        }
 
        XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(
                XPropertySet.class, oConfig);
        try {
            // change some properties
 
            /**
             * The first property specifies that the resolution of each image
             * must be reduced to the resolution specified by the second property
             * The value is given in DPI.
             */
            xPropertySet.setPropertyValue("ReduceImageResolution", Boolean.TRUE);
            xPropertySet.setPropertyValue("MaxImageResolution", new Integer(600));
 
            /**
             * When exporting a document to PDF, the default is PDF 1.4
             * Since OOo 2.4 the PDF/A-1a is also supported.
             * PDF/A-1a is an ISO 19005-1:2005 International Standard.
             * 
             * NOTE that some other options WILL NOT be available if this format
             * is selected (UseTaggedPDF, ExportFormFileds, FormsType,
             * all security options)
             */
            xPropertySet.setPropertyValue("SelectPdfVersion", new Integer(1));
 
            /**
             * "Magnification" specifies the action to be performed 
             * when the PDF document is opened.
             * A value of 4 opens with the zoom level specified in the 
             * "Zoom" property.
             */
            xPropertySet.setPropertyValue("Magnification", new Integer(4));
            xPropertySet.setPropertyValue("Zoom", new Integer(60));
 
            //you must commit the changes, if not they will be lost
            XChangesBatch xChangesBatch = (XChangesBatch) UnoRuntime.queryInterface(
                    XChangesBatch.class, xPropertySet);
 
            xChangesBatch.commitChanges();
 
        } catch (UnknownPropertyException ex) {
            ex.printStackTrace();
        } catch (PropertyVetoException ex) {
            ex.printStackTrace();
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch (WrappedTargetException ex) {
            ex.printStackTrace();
        }
    }
 
    public static Object getPDFConfigUpdateAccess(XComponentContext xContext){
 
        Object oPDFExportConfig = null;
        try {
 
            XMultiComponentFactory xMCF = xContext.getServiceManager();
 
            Object oConfigProvider = xMCF.createInstanceWithContext(
                    "com.sun.star.configuration.ConfigurationProvider", xContext);
 
            XMultiServiceFactory oConfigProvMSF = 
                    (XMultiServiceFactory) UnoRuntime.queryInterface(
                XMultiServiceFactory.class, oConfigProvider);
 
            PropertyValue[] args = new PropertyValue[1];
 
            args[0] = new PropertyValue();
            args[0].Name = "nodepath";
            args[0].Value = "/org.openoffice.Office.Common/Filter/PDF/Export/";
 
            // ConfigurationUpdateAccess instead of ConfigurationAccess
            String sServiceName = "com.sun.star.configuration.ConfigurationUpdateAccess";
 
            oPDFExportConfig = oConfigProvMSF.createInstanceWithArguments(
                    sServiceName, args);
 
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return oPDFExportConfig;
        }
    }
 
 
}

Resetting the configuration

ToDo


PDF Export Dialog

How to use it from Java

ToDo


How to use it from C++

ToDo


How to use it from OOo Basic

ToDo

Personal tools