使用 jython 和 open office 2.4 将文档转换为 pdf

发布于 2024-07-08 13:37:57 字数 1861 浏览 6 评论 0 原文

我使用 pyuno 完成了一个 python 脚本,它成功地将文档/ xls / rtf 等转换为 pdf。 然后我需要更新一个mssql数据库,由于open office目前支持python 2.3,它很古老,缺乏对像样的数据库库的支持。 所以我求助于使用 Jython,这样我就不会因为使用旧的 pyuno 在 OO python 环境中运行而感到负担。

这也意味着我的转换代码已损坏,我现在需要使用 java 库而不是 pyuno 库。

导入 com.sun.star.beans.PropertyValue 作为 PropertyValue
将 com.sun.star.bridge.XUnoUrlResolver 导入为 XUnoUrlResolver
将 com.sun.star.comp.helper.Bootstrap 导入为 Bootstrap
->> 导入 com.sun.star.frame.XComponentLoader 作为 XComponentLoader
->> 将 com.sun.star.frame.XStorable 导入为 XStorable
导入 com.sun.star.lang.XMultiComponentFactory 作为 XMultiComponentFactory
将 com.sun.star.uno.UnoRuntime 导入为 UnoRuntime
导入 com.sun.star.uno.XComponentContext 作为 XComponentContext

包含带有 '->>' 的内容 不导入,编译器无法识别 com.sun.star.frame,看不到“frame”位。 这些是我包含的库。

替代文本 http://www.freeimagehosting.net/uploads/eda5cda76d.jpg

一些关于这个问题的建议会很受欢迎

上下文 = XComponentContext
xMultiCompFactory = XMultiComponentFactory
xComponentLoader = XComponentLoader

//在python中使用
ctx = 无
smgr = 无
文档=无
网址=无

上下文 = Bootstrap.bootstrap()
xMultiCompFactory = self.context.getServiceManager()
xcomponentloader = UnoRuntime.queryInterface(XComponentLoader.class, ....xMultiCompFactory.createInstanceWithContext("com.sun.star.frame.Desktop", context))

文件=“文件:\\”+文件
// 另外,Java 中 url = uno.systemPathToFileUrl(file) 的等价物是什么,以便我可以利用它来很好地格式化我的路径
属性 = []
p = PropertyValue()
p.Name =“隐藏”
p.Value = True
属性.append(p)
属性=元组(属性)
doc = xcomponentloader.loadComponentFromURL(file, "_blank",0, 属性)

I completed a python script using pyuno which successfully converted a document/ xls / rtf etc to a pdf.
Then I needed to update a mssql database, due to open office currently supporting python 2.3, it's ancientness, lacks support for decent database libs. So I have resorted to using Jython, this way im not burdened down by running inside OO python environment using an old pyuno.

This also means that my conversion code is broken, and I need to now make use of the java libraries instead of the pyuno libs.

import com.sun.star.beans.PropertyValue as PropertyValue
import com.sun.star.bridge.XUnoUrlResolver as XUnoUrlResolver
import com.sun.star.comp.helper.Bootstrap as Bootstrap
->> import com.sun.star.frame.XComponentLoader as XComponentLoader
->> import com.sun.star.frame.XStorable as XStorable
import com.sun.star.lang.XMultiComponentFactory as XMultiComponentFactory
import com.sun.star.uno.UnoRuntime as UnoRuntime
import com.sun.star.uno.XComponentContext as XComponentContext

The includes with the '->>' do not import the compiler does not recognise the com.sun.star.frame cant see the 'frame' bit. These are the libs I have included.

alt text http://www.freeimagehosting.net/uploads/eda5cda76d.jpg

Some advice on this matter would be well received

context = XComponentContext
xMultiCompFactory = XMultiComponentFactory
xcomponentloader = XComponentLoader

//used in python
ctx = None
smgr = None
doc = None
url = None

context = Bootstrap.bootstrap()
xMultiCompFactory = self.context.getServiceManager()
xcomponentloader = UnoRuntime.queryInterface(XComponentLoader.class, ....xMultiCompFactory.createInstanceWithContext("com.sun.star.frame.Desktop", context))

file = "file:\\" + file
// also what is the equivalent of url = uno.systemPathToFileUrl(file) in Java so that I can make use of it to nicely format my path
properties = []
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties.append(p)
properties = tuple(properties)
doc = xcomponentloader.loadComponentFromURL(file, "_blank",0, properties)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏夜暖风 2024-07-15 13:37:57

所以,根据这个人的说法,你需要一些油......它就像一个魅力

http://www.oooforum.org/forum/viewtopic.phtml?p=304263#304263

包含此库 C:\OpenOffice_24\program\classes\unoil.jar

And so it goes, according to this guy, you need some oil.... and it works like a charm

http://www.oooforum.org/forum/viewtopic.phtml?p=304263#304263

include this lib C:\OpenOffice_24\program\classes\unoil.jar

反目相谮 2024-07-15 13:37:57

我认为使用 Jython 是一个好主意。 但是为什么你不能使用两个脚本,一个使用 pyuno/2.3,另一个使用 pymssql/2.5(或你正在使用的任何数据库适配器)?

中间格式可以是 pickle、json 或 XML 之类的任何格式。

编辑:我应该补充一点,我已经广泛使用了 pyuno,我感受到你的痛苦。

Using Jython is a great idea for this I think. But why could you not use two scripts, one with pyuno/2.3 and one with pymssql/2.5 (or whatever db adapter you are using)?.

The intermediate format could be anything like a pickle, or json, or XML.

Edit: I should add that I have used pyuno quite extensively, and I feel your pain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文