Hello Zak,
On Sunday 27 December 2009, 21:30, Zak McKracken wrote:
> This goes to the OOo.general group (where the thing started) as well as to
> the OOo.scripting one, where it is probably better placed.
no, for OOo API questions the best place is the API mailing list
[email protected]
> What did not work was the part where I tried to specify pdf conversion
> options in the basic script (appended in the comments of the python
> script).
> Here's the part of the basic script that does the conversion:
> <code>
> oDoc.storeToURL( cURL, Array(_
> MakePropertyValue( "FilterName", "writer_pdf_Export" ),))
> </code>
> I expected to be able to influence the options by doing something like
> <code>
> oDoc.storeToURL( cURL, Array(_
> MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
> MakePropertyValue( "ReduceImageResolution", TRUE ),))
> </code>
> , but that seems to be wrong, the parameters are ignored.
> In the example from
> http://wiki.services.openoffice.org/wiki/API/Tutorials/PDF_export#Filter_da
> ta_demo only one single array of parameters is passed to the pdf export
> filter, but either there is something wrong with the example or I didn't
> quite get it.
nothing's wrong with the example, so you didn't quite get it.
Re-read the Java code.
I quote myself (I was the one who wrote the tutorial):
XStorable.storeToURL() expects an URL as first parameter, and an array of
com.sun.star.beans.PropertyValue structs as second parameter, which implements
the com.sun.star.document.MediaDescriptor service, consisting of property
definitions. The media descriptor is used for loading/importing and
saving/exporting documents, please refer to the Developer's Guide for a
detailed explanation. In this case, it includes only the struct for the
FilterName, indicating the name of the filter for exporting Writer documents to
PDF.
You can fully customize the PDF export process by adding another PropertyValue
struct to the MediaDescriptor array: FilterData. This parameter is used to
pass properties specific for a special filter type. In the case of the PDF
export filter, another array of PropertyValue structs is expected.
Try the Python code attached (needs to start OOo in listening mode,
instructions at the top of the file).
Regards
--
Ariel Constenla-Haile
La Plata, Argentina
# -*- coding: utf-8 -*-
# sample client application
#
# Start OOo with the following command:
# /opt/openoffice.org3/program/soffice "-accept=socket,host=localhost,port=8100;urp;StarOffice.ComponentContext" > /dev/null 2>&1 &
import uno
import unohelper
from com.sun.star.beans import NamedValue
from com.sun.star.beans import PropertyValue
from com.sun.star.beans.PropertyState import DIRECT_VALUE
def get_pdf_config_access( xContext ):
"""Access the PDF configuration."""
xConfigurationProvider = xContext.ServiceManager.createInstanceWithContext(
"com.sun.star.configuration.ConfigurationProvider", xContext )
aNamedValue = NamedValue()
aNamedValue.Name = "nodepath"
aNamedValue.Value = "/org.openoffice.Office.Common/Filter/PDF/Export/"
xConfigurationUpdateAccess = xConfigurationProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess", (aNamedValue,) )
return xConfigurationUpdateAccess
def load_new_writer_doc( xContext ):
xComponentLoader = xContext.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext )
xComponent = xComponentLoader.loadComponentFromURL(
"private:factory/swriter", "_default", 0, () )
return xComponent
def get_home_dir( xContext ):
xPathSubst = xContext.ServiceManager.createInstanceWithContext(
"com.sun.star.util.PathSubstitution", xContext )
sHomeDir = xPathSubst.getSubstituteVariableValue( "$(home)" )
return sHomeDir
def create_unique_file_name( xContext, sBaseURL, sFileName, sExtension ):
xSFA = xContext.ServiceManager.createInstanceWithContext(
"com.sun.star.ucb.SimpleFileAccess", xContext )
n = 0
sRet = sBaseURL + "/" + sFileName + "." + sExtension
while xSFA.exists( sRet ) :
sRet = sBaseURL + "/" + sFileName + str(n) + "." + sExtension
n = n + 1
return sRet
sConnectionStr = "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext"
localContext = uno.getComponentContext()
localServiceManager = localContext.getServiceManager()
xURLResolver = localServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
remoteContext = xURLResolver.resolve( sConnectionStr )
remoteServiceManager = remoteContext.getServiceManager()
###############################################################################
#
# PDF Configuration demo
#
xPDFConfig = get_pdf_config_access( remoteContext )
xPDFConfig.setPropertyValue("ReduceImageResolution", True)
xPDFConfig.setPropertyValue("MaxImageResolution", 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)
xPDFConfig.setPropertyValue("SelectPdfVersion", 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.
xPDFConfig.setPropertyValue("Magnification", 4)
xPDFConfig.setPropertyValue("Zoom", 60)
# When using XMultiPropertySet:setPropertyValues(),
# properties must be alphabetically sorted!
xPDFConfig.setPropertyValues(
( "CenterWindow", "DisplayPDFDocumentTitle", "InitialView", "PageLayout" ),
( True, False, 2, 1 )
)
# commit the changes, otherwise they will be lost!
xPDFConfig.commitChanges()
#############################################################################
#
# FilterData demo
#
xTextDoc = load_new_writer_doc( remoteContext )
xTextDoc.getText().setString( "This a demo to be exported as PDF." )
sURL = create_unique_file_name(
remoteContext,
get_home_dir( remoteContext ),
"PDF_export_demo",
"pdf" )
aFilterData = (
PropertyValue( "DisplayPDFDocumentTitle", -1, False, DIRECT_VALUE ),
PropertyValue( "OpenInFullScreenMode", -1, True, DIRECT_VALUE )
)
# Exporting to PDF consists of giving the proper
# filter name in the property "FilterName"
# By adding the "FilterData" we can control what is exported and how
aMediaDescriptor = (
PropertyValue( "FilterName", -1, "writer_pdf_Export", DIRECT_VALUE ),
PropertyValue( "FilterData", -1, aFilterData, DIRECT_VALUE )
)
xTextDoc.storeToURL( sURL, aMediaDescriptor )
xTextDoc.close( True )
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]