Hi,
the attached patch works for me. Give it a try.
Bye,
Joerg
Ariel Constenla-Haile wrote:
Hi there,
In Python, I need to transport a css::uno::Sequence<css::beans::PropertyValue>
inside the css.document.MediaDescriptor's FilterData for the PDF export filter.
I guess (my PyUNO knowledge is rather limited... as I don't like Python that
much...) the Python code may look like this:
aFilterData = (
PropertyValue( "DisplayPDFDocumentTitle", 0, False, DIRECT_VALUE ),
PropertyValue( "OpenInFullScreenMode", 0, True, DIRECT_VALUE ),
PropertyValue( "ResizeWindowToInitialPage", 0, True, DIRECT_VALUE ),
PropertyValue( "HideViewerMenubar", 0, True, DIRECT_VALUE ),
PropertyValue( "HideViewerToolbar", 0, True, DIRECT_VALUE ),
PropertyValue( "Selection", 0, oSel, DIRECT_VALUE )
)
aMediaDescriptor = (
PropertyValue( "FilterName", 0, "writer_pdf_Export", DIRECT_VALUE ),
PropertyValue( "FilterData", 0, aFilterData, DIRECT_VALUE )
)
xTextDoc.storeToURL( sURL, aMediaDescriptor )
(complete code attached)
what in Java looks like this:
PropertyValue[] aMediaDescriptor = new PropertyValue[2];
aMediaDescriptor[0] = new PropertyValue();
aMediaDescriptor[0].Name = "FilterName";
aMediaDescriptor[0].Value = "writer_pdf_Export";
PropertyValue[] aFilterData = new PropertyValue[6];
aFilterData[0] = new PropertyValue();
aFilterData[0].Name = "Selection";
aFilterData[0].Value = oSelection;
aFilterData[1] = new PropertyValue();
aFilterData[1].Name = "DisplayPDFDocumentTitle";
aFilterData[1].Value = Boolean.FALSE;
aFilterData[2] = new PropertyValue();
aFilterData[2].Name = "OpenInFullScreenMode";
aFilterData[2].Value = Boolean.TRUE;
aFilterData[3] = new PropertyValue();
aFilterData[3].Name = "ResizeWindowToInitialPage";
aFilterData[3].Value = Boolean.TRUE;
aFilterData[4] = new PropertyValue();
aFilterData[4].Name = "HideViewerMenubar";
aFilterData[4].Value = Boolean.TRUE;
aFilterData[5] = new PropertyValue();
aFilterData[5].Name = "HideViewerToolbar";
aFilterData[5].Value = Boolean.TRUE;
aMediaDescriptor[1] = new PropertyValue();
aMediaDescriptor[1].Name = "FilterData";
aMediaDescriptor[1].Value = aFilterData;
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, xTextDocument);
xStorable.storeToURL(sURL, aMediaDescriptor);
and in OOo Basic looks like the code in
http://arielch.fedorapeople.org/docs/PDF_export_FilterData_demo.odt
The problem is that with the above code, the PyUNO bridge transports the
FilterData as a css::uno::Sequence<css::uno::Any> instead of a
css::uno::Sequence<css::beans::PropertyValue> and the convertion fails in the
filter code
http://svn.services.openoffice.org/opengrok/xref/DEV300_m68/filter/source/pdf/pdffilter.cxx#71
so that the filter ends up reading the configuration instead of the FilterData
passed.
The problem is the same as in
http://www.openoffice.org/issues/show_bug.cgi?id=12504
"The problem is, that the writer code expects a
sequence<PropertyValue> as the any argument of replaceByIndex, but
python delivers a sequence<any>, where each member is of type
PropertyValue."
but the workaround in FAQ Nr. 15 didn't work for me cf.
http://udk.openoffice.org/python/python-bridge.html#faq and
http://www.openoffice.org/issues/show_bug.cgi?id=12504#desc12
Any hints on how to tell the PyUNO bridge to do things as really wanted are
very welcome.
Regards
------------------------------------------------------------------------
# -*- 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
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
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()
#############################################################################
#############################################################################
#
# FilterData demo
#
xTextDoc = load_new_writer_doc( remoteContext )
xText = xTextDoc.getText()
xCursor = xText.createTextCursorByRange( xText.getStart() )
xText.insertString( xCursor, "This is a demo", False )
xText.insertControlCharacter( xCursor, PARAGRAPH_BREAK, False )
xText.insertString( xCursor, "to be exported as PDF" , True )
xTextDoc.getCurrentController().select( xCursor )
oSel = xTextDoc.getCurrentController().getSelection()
sURL = create_unique_file_name(
remoteContext,
get_home_dir( remoteContext ),
"PDF_export_demo",
"pdf" )
aFilterData = (
PropertyValue( "DisplayPDFDocumentTitle", 0, False,
DIRECT_VALUE ),
PropertyValue( "OpenInFullScreenMode", 0, True,
DIRECT_VALUE ),
PropertyValue( "ResizeWindowToInitialPage", 0, True,
DIRECT_VALUE ),
PropertyValue( "HideViewerMenubar", 0, True,
DIRECT_VALUE ),
PropertyValue( "HideViewerToolbar", 0, True,
DIRECT_VALUE ),
PropertyValue( "Selection", 0, oSel,
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", 0, "writer_pdf_Export",
DIRECT_VALUE ),
PropertyValue( "FilterData", 0, aFilterData,
DIRECT_VALUE )
)
xTextDoc.storeToURL( sURL, aMediaDescriptor )
xTextDoc.close( True )
print "Stored as " + sURL
------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org
*** pdf_filterdata.py.orig Mon Dec 28 22:05:28 2009
--- pdf_filterdata.py Mon Dec 28 22:07:27 2009
***************
*** 89,98 ****
# By adding the "FilterData" we can control what is exported and how
aMediaDescriptor = (
PropertyValue( "FilterName", 0, "writer_pdf_Export",
DIRECT_VALUE ),
! PropertyValue( "FilterData", 0, aFilterData,
DIRECT_VALUE )
)
! xTextDoc.storeToURL( sURL, aMediaDescriptor )
xTextDoc.close( True )
print "Stored as " + sURL
--- 89,98 ----
# By adding the "FilterData" we can control what is exported and how
aMediaDescriptor = (
PropertyValue( "FilterName", 0, "writer_pdf_Export",
DIRECT_VALUE ),
! PropertyValue( "FilterData", 0, uno.Any(
"[]com.sun.star.beans.PropertyValue", aFilterData), DIRECT_VALUE )
)
! uno.invoke( xTextDoc, "storeToURL", ( sURL, aMediaDescriptor) )
xTextDoc.close( True )
print "Stored as " + sURL
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org