pyuno and PDF output

w chun wescpy at gmail.com
Sat Jun 24 02:54:26 CEST 2006


> Subject: pyuno and PDF output
> From: "Sells, Fred" <fred at adventistcare.org>
> Date: Thu May 4 19:20:57 CEST 2006
>
> I can use java to output a PDF file using uno, but when I try to do it in
> python, I get an IO Exception with no added information.   The relevant code
> snippet follows:
>
> from com.sun.star.beans import PropertyValue
> PDF    = PropertyValue( "FilterName" , 0 , "writer_pdf_Export", 0 )
> doc2.storeAsURL("file:///C:/alleclipse/OpenOffice/test2.pdf", (PDF,) )
>
> if I don't specify any properties, it writes an "odt" file just fine, but
> when I specify (PDF,) it breaks.
>
> Traceback (most recent call last):
>   File "oomerge.py", line 137, in ?
>     test1()
>   File "oomerge.py", line 74, in test1
>     doc2.storeAsURL("file:///C:/alleclipse/OpenOffice/test2.pdf", (PDF,) )
> __main__.com.sun.star.task.ErrorCodeIOException


fred,

(man, i hate seeing that error too... it gets old *fast*.)
a couple of suggestions here:

1. use unohelper with filenames (see #3 below)
    import unohelper

2. use the short form to instantiate a PropertyValue

    REPLACE:
	PDF = PropertyValue("FilterName", 0, "writer_pdf_Export", 0)

    WITH:
	PDF = PropertyValue("FilterName", "writer_pdf_Export")

3. use storeToURL() as opposed to storeAsURL()

    REPLACE:
	doc2.storeAsURL("file:///C:/alleclipse/OpenOffice/test2.pdf", (PDF,))

    WITH:
	doc2.storeToURL(unohelper.absolutize(
	    unohelper.systemPathToFileUrl('C:/alleclipse/OpenOffice/test2.pdf'),
	    unohelper.systemPathToFileUrl('test2.pdf')), (PDF,))

let us know how/if/whether this works.

HTH,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com



More information about the Python-list mailing list