当前位置: 首页 > news >正文

云南省建设厅建管处网站最好的seo外包

云南省建设厅建管处网站,最好的seo外包,公司主页怎么填,网站设计论文答辩Linux中使用命令行方式调用openoffice服务将word文件转为PDF 测试安装之后的openoffice用命令将docx文件转换为PDF 需要一份python的脚本程序,因为转换需要通过py程序去调用api处理,将下面程序保存到topdf.py文件: # # PyODConverter (Pyth…

Linux中使用命令行方式调用openoffice服务将word文件转为PDF

测试安装之后的openoffice用命令将docx文件转换为PDF

 

需要一份python的脚本程序,因为转换需要通过py程序去调用api处理,将下面程序保存到topdf.py文件:

#
# PyODConverter (Python OpenDocument Converter) v1.1 - 2009-11-14
#
# This script converts a document from one office format to another by
# connecting to an OpenOffice.org instance via Python-UNO bridge.
#
# Copyright (C) 2008-2009 Mirko Nasato <mirko@artofsolving.com>
# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl-2.1.html
# - or any later version.
#
DEFAULT_OPENOFFICE_PORT = 8100import uno
from os.path import abspath, isfile, splitext
from com.sun.star.beans import PropertyValue
from com.sun.star.task import ErrorCodeIOException
from com.sun.star.connection import NoConnectExceptionFAMILY_TEXT = "Text"
FAMILY_WEB = "Web"
FAMILY_SPREADSHEET = "Spreadsheet"
FAMILY_PRESENTATION = "Presentation"
FAMILY_DRAWING = "Drawing"#---------------------#
# Configuration Start #
#---------------------## see http://wiki.services.openoffice.org/wiki/Framework/Article/Filter# most formats are auto-detected; only those requiring options are defined here
IMPORT_FILTER_MAP = {"txt": {"FilterName": "Text (encoded)","FilterOptions": "utf8"},"csv": {"FilterName": "Text - txt - csv (StarCalc)","FilterOptions": "44,34,0"}
}EXPORT_FILTER_MAP = {"pdf": {FAMILY_TEXT: { "FilterName": "writer_pdf_Export" },FAMILY_WEB: { "FilterName": "writer_web_pdf_Export" },FAMILY_SPREADSHEET: { "FilterName": "calc_pdf_Export" },FAMILY_PRESENTATION: { "FilterName": "impress_pdf_Export" },FAMILY_DRAWING: { "FilterName": "draw_pdf_Export" }},"html": {FAMILY_TEXT: { "FilterName": "HTML (StarWriter)" },FAMILY_SPREADSHEET: { "FilterName": "HTML (StarCalc)" },FAMILY_PRESENTATION: { "FilterName": "impress_html_Export" }},"odt": {FAMILY_TEXT: { "FilterName": "writer8" },FAMILY_WEB: { "FilterName": "writerweb8_writer" }},"doc": {FAMILY_TEXT: { "FilterName": "MS Word 97" }},"rtf": {FAMILY_TEXT: { "FilterName": "Rich Text Format" }},"txt": {FAMILY_TEXT: {"FilterName": "Text","FilterOptions": "utf8"}},"ods": {FAMILY_SPREADSHEET: { "FilterName": "calc8" }},"xls": {FAMILY_SPREADSHEET: { "FilterName": "MS Excel 97" }},"csv": {FAMILY_SPREADSHEET: {"FilterName": "Text - txt - csv (StarCalc)","FilterOptions": "44,34,0"}},"odp": {FAMILY_PRESENTATION: { "FilterName": "impress8" }},"ppt": {FAMILY_PRESENTATION: { "FilterName": "MS PowerPoint 97" }},"swf": {FAMILY_DRAWING: { "FilterName": "draw_flash_Export" },FAMILY_PRESENTATION: { "FilterName": "impress_flash_Export" }}
}PAGE_STYLE_OVERRIDE_PROPERTIES = {FAMILY_SPREADSHEET: {#--- Scale options: uncomment 1 of the 3 ---# a) 'Reduce / enlarge printout': 'Scaling factor'"PageScale": 100,# b) 'Fit print range(s) to width / height': 'Width in pages' and 'Height in pages'#"ScaleToPagesX": 1, "ScaleToPagesY": 1000,# c) 'Fit print range(s) on number of pages': 'Fit print range(s) on number of pages'#"ScaleToPages": 1,"PrintGrid": False}
}#-------------------#
# Configuration End #
#-------------------#class DocumentConversionException(Exception):def __init__(self, message):self.message = messagedef __str__(self):return self.messageclass DocumentConverter:def __init__(self, port=DEFAULT_OPENOFFICE_PORT):localContext = uno.getComponentContext()resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)try:context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port)except NoConnectException:raise DocumentConversionException, "failed to connect to OpenOffice.org on port %s" % portself.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)def convert(self, inputFile, outputFile):inputUrl = self._toFileUrl(inputFile)outputUrl = self._toFileUrl(outputFile)loadProperties = { "Hidden": True }inputExt = self._getFileExt(inputFile)if IMPORT_FILTER_MAP.has_key(inputExt):loadProperties.update(IMPORT_FILTER_MAP[inputExt])document = self.desktop.loadComponentFromURL(inputUrl, "_blank", 0, self._toProperties(loadProperties))try:document.refresh()except AttributeError:passfamily = self._detectFamily(document)self._overridePageStyleProperties(document, family)outputExt = self._getFileExt(outputFile)storeProperties = self._getStoreProperties(document, outputExt)try:document.storeToURL(outputUrl, self._toProperties(storeProperties))finally:document.close(True)def _overridePageStyleProperties(self, document, family):if PAGE_STYLE_OVERRIDE_PROPERTIES.has_key(family):properties = PAGE_STYLE_OVERRIDE_PROPERTIES[family]pageStyles = document.getStyleFamilies().getByName('PageStyles')for styleName in pageStyles.getElementNames():pageStyle = pageStyles.getByName(styleName)for name, value in properties.items():pageStyle.setPropertyValue(name, value)def _getStoreProperties(self, document, outputExt):family = self._detectFamily(document)try:propertiesByFamily = EXPORT_FILTER_MAP[outputExt]except KeyError:raise DocumentConversionException, "unknown output format: '%s'" % outputExttry:return propertiesByFamily[family]except KeyError:raise DocumentConversionException, "unsupported conversion: from '%s' to '%s'" % (family, outputExt)def _detectFamily(self, document):if document.supportsService("com.sun.star.text.WebDocument"):return FAMILY_WEBif document.supportsService("com.sun.star.text.GenericTextDocument"):# must be TextDocument or GlobalDocumentreturn FAMILY_TEXTif document.supportsService("com.sun.star.sheet.SpreadsheetDocument"):return FAMILY_SPREADSHEETif document.supportsService("com.sun.star.presentation.PresentationDocument"):return FAMILY_PRESENTATIONif document.supportsService("com.sun.star.drawing.DrawingDocument"):return FAMILY_DRAWINGraise DocumentConversionException, "unknown document family: %s" % documentdef _getFileExt(self, path):ext = splitext(path)[1]if ext is not None:return ext[1:].lower()def _toFileUrl(self, path):return uno.systemPathToFileUrl(abspath(path))def _toProperties(self, dict):props = []for key in dict:prop = PropertyValue()prop.Name = keyprop.Value = dict[key]props.append(prop)return tuple(props)if __name__ == "__main__":from sys import argv, exitif len(argv) < 3:print "USAGE: python %s <input-file> <output-file>" % argv[0]exit(255)if not isfile(argv[1]):print "no such input file: %s" % argv[1]exit(1)try:converter = DocumentConverter()    converter.convert(argv[1], argv[2])except DocumentConversionException, exception:print "ERROR! " + str(exception)exit(1)except ErrorCodeIOException, exception:print "ERROR! ErrorCodeIOException %d" % exception.ErrCodeexit(1)

将文件保存到program目录下面,然后就可以执行转换命令了:

[root@ program]# ./python topdf.py /opt/openoffice4/test.docx /opt/openoffice4/test.pdf

同样的命令也可以转换其它格式的文件,若转化出来的文档乱码,可能是服务器上缺少字体。

相对来说,libreoffice实现起来要比openoffice会简单点。

http://www.lbrq.cn/news/2606275.html

相关文章:

  • ic交易网站建设推广公众号
  • wordpress根目录403专业关键词排名优化软件
  • 猎头网站怎么做seo免费培训教程
  • 电子商务网站开发规划百度百度地图
  • 可信赖的手机网站建设百度网站首页网址
  • 方微商城网站开发电商网站首页
  • 千图网人工客服百度关键词怎么优化
  • 泊头哪给做网站的好营业推广策略有哪些
  • 沈阳网站建设推广平台网站推广入口
  • 做网站克隆企业营销推广怎么做
  • 做儿童网站赚钱吗建一个自己的网站
  • 网页设计尺寸的分辨率南昌seo报价
  • 英文外贸网站在线观看的seo综合查询
  • 水果网站推广资源链接搜索引擎
  • 黄冈商城网站建设哪家好seo网站推广批发
  • 永久免费建个人网站seo外包公司兴田德润官方地址
  • 东莞做网站建设百度榜单
  • 旅社网站建设百度推广没有一点效果
  • 公司网站首页布局图搜一搜搜索
  • 竞网做的网站怎么样百度推广方式有哪些
  • 温州网站制作价格南宁seo优化公司排名
  • 网站运营谁都可以做吗百度知道
  • 家具行业做那个国际网站比较好2022磁力链接搜索引擎推荐
  • 做科学小制作的视频网站长沙市网站制作
  • 企业建网站的少了网络营销推广处点
  • 单页网站多钱河北百度竞价优化
  • 广州比较好的网站建设企业南宁网站建设网络公司
  • 做按摩网站违法吗南宁网络推广外包
  • 天津电商网站开发搜索词排行榜
  • 鹰潭市网站建设公司潍坊关键词优化平台
  • 华硕携多款明星电竞显示器亮相 ChinaJoy2025,联袂 TCL 华星打造沉浸体验
  • 【机器学习】算法调参的两种方式:网格搜索(枚举)、随机搜索
  • uniapp基础(五)调试与错误
  • 【原创】基于gemini-2.5-flash-preview-05-20多模态模型实现短视频的自动化二创
  • Linux操作系统从入门到实战(十三)版本控制器Git基础概念讲解
  • Linux84 SHELL编程:流程控制 前瞻(1)