生成和发布python客户端
pp.client-python的Python项目详细描述
pp.client-python
为python生成和发布绑定。
pp.client-python绑定可用于通信 使用product&publish server pp.server 生成 来自python应用程序或用于进行文档转换的pdf 使用unconv(libreoffice或libreoffice的包装器)。
要求
- 巨蟒3.5
- python 3.6
API
PDF API
pdf的api支持html/xml到pdf的转换 通过以下PDF转换器:
- PDFreactor 7+(商用)
- PrinceXML 9+(商用)
- Speedata发行商(免费)
- 幻影(免费)
- VillioStyle格式化程序(免费)
pdf转换过程基于"css paged media"方法 其中输入文档(XML或HTML)仅使用CSS设置样式。
pp.client-python的 pdf api期望输入 文件和所有相关资产(图像、样式表、字体文件等) 放在工作目录中。输入文件必须命名为 index.html
使用命令行前端:
$ ../bin/pp-pdf --help usage: pp-pdf [-h] [-f princexml] [-o] [-a] [-s http://localhost:6543] [-t None] [-c] [-v] source_directory [cmd_options] positional arguments: source_directory Source directory containing content and assets to be converted cmd_options [] optional arguments: -h, --help show this help message and exit -f princexml, --converter princexml PDF converter to be used (princexml, pdfreactor, publisher) -o , --output Write result ZIP to given .zip filename -s http://localhost:6543, --server-url http://localhost:6543 URL of Produce & Publish server) -t None, --authorization-token None Authorization token for P&P server -v, --verbose Verbose mode
任何python应用程序都可以通过 pdf() p p.client-python模块的api:
from pp.client.python.pdf import pdf def pdf(source_directory, converter='princexml', output='', cmd_options='', server_url='http://localhost:6543', authorization_token=None, verbose=False):
优尼科API
unconv的api提供了一个通用的转换api 对于各种格式(由下面的libreoffice支持 后台服务:
The following list of document formats are currently available: bib - BibTeX [.bib] doc - Microsoft Word 97/2000/XP [.doc] doc6 - Microsoft Word 6.0 [.doc] doc95 - Microsoft Word 95 [.doc] docbook - DocBook [.xml] docx - Microsoft Office Open XML [.docx] docx7 - Microsoft Office Open XML [.docx] fodt - OpenDocument Text (Flat XML) [.fodt] html - HTML Document (OpenOffice.org Writer) [.html] latex - LaTeX 2e [.ltx] mediawiki - MediaWiki [.txt] odt - ODF Text Document [.odt] ooxml - Microsoft Office Open XML [.xml] ott - Open Document Text [.ott] pdb - AportisDoc (Palm) [.pdb] pdf - Portable Document Format [.pdf] psw - Pocket Word [.psw] rtf - Rich Text Format [.rtf] sdw - StarWriter 5.0 [.sdw] sdw4 - StarWriter 4.0 [.sdw] sdw3 - StarWriter 3.0 [.sdw] stw - Open Office.org 1.0 Text Document Template [.stw] sxw - Open Office.org 1.0 Text Document [.sxw] text - Text Encoded [.txt] txt - Text [.txt] uot - Unified Office Format text [.uot] vor - StarWriter 5.0 Template [.vor] vor4 - StarWriter 4.0 Template [.vor] vor3 - StarWriter 3.0 Template [.vor] xhtml - XHTML Document [.html] The following list of graphics formats are currently available: bmp - Windows Bitmap [.bmp] emf - Enhanced Metafile [.emf] eps - Encapsulated PostScript [.eps] fodg - OpenDocument Drawing (Flat XML) [.fodg] gif - Graphics Interchange Format [.gif] html - HTML Document (OpenOffice.org Draw) [.html] jpg - Joint Photographic Experts Group [.jpg] met - OS/2 Metafile [.met] odd - OpenDocument Drawing [.odd] otg - OpenDocument Drawing Template [.otg] pbm - Portable Bitmap [.pbm] pct - Mac Pict [.pct] pdf - Portable Document Format [.pdf] pgm - Portable Graymap [.pgm] png - Portable Network Graphic [.png] ppm - Portable Pixelmap [.ppm] ras - Sun Raster Image [.ras] std - OpenOffice.org 1.0 Drawing Template [.std] svg - Scalable Vector Graphics [.svg] svm - StarView Metafile [.svm] swf - Macromedia Flash (SWF) [.swf] sxd - OpenOffice.org 1.0 Drawing [.sxd] sxd3 - StarDraw 3.0 [.sxd] sxd5 - StarDraw 5.0 [.sxd] sxw - StarOffice XML (Draw) [.sxw] tiff - Tagged Image File Format [.tiff] vor - StarDraw 5.0 Template [.vor] vor3 - StarDraw 3.0 Template [.vor] wmf - Windows Metafile [.wmf] xhtml - XHTML [.xhtml] xpm - X PixMap [.xpm] The following list of presentation formats are currently available: bmp - Windows Bitmap [.bmp] emf - Enhanced Metafile [.emf] eps - Encapsulated PostScript [.eps] fodp - OpenDocument Presentation (Flat XML) [.fodp] gif - Graphics Interchange Format [.gif] html - HTML Document (OpenOffice.org Impress) [.html] jpg - Joint Photographic Experts Group [.jpg] met - OS/2 Metafile [.met] odg - ODF Drawing (Impress) [.odg] odp - ODF Presentation [.odp] otp - ODF Presentation Template [.otp] pbm - Portable Bitmap [.pbm] pct - Mac Pict [.pct] pdf - Portable Document Format [.pdf] pgm - Portable Graymap [.pgm] png - Portable Network Graphic [.png] potm - Microsoft PowerPoint 2007/2010 XML Template [.potm] pot - Microsoft PowerPoint 97/2000/XP Template [.pot] ppm - Portable Pixelmap [.ppm] pptx - Microsoft PowerPoint 2007/2010 XML [.pptx] pps - Microsoft PowerPoint 97/2000/XP (Autoplay) [.pps] ppt - Microsoft PowerPoint 97/2000/XP [.ppt] pwp - PlaceWare [.pwp] ras - Sun Raster Image [.ras] sda - StarDraw 5.0 (OpenOffice.org Impress) [.sda] sdd - StarImpress 5.0 [.sdd] sdd3 - StarDraw 3.0 (OpenOffice.org Impress) [.sdd] sdd4 - StarImpress 4.0 [.sdd] sxd - OpenOffice.org 1.0 Drawing (OpenOffice.org Impress) [.sxd] sti - OpenOffice.org 1.0 Presentation Template [.sti] svg - Scalable Vector Graphics [.svg] svm - StarView Metafile [.svm] swf - Macromedia Flash (SWF) [.swf] sxi - OpenOffice.org 1.0 Presentation [.sxi] tiff - Tagged Image File Format [.tiff] uop - Unified Office Format presentation [.uop] vor - StarImpress 5.0 Template [.vor] vor3 - StarDraw 3.0 Template (OpenOffice.org Impress) [.vor] vor4 - StarImpress 4.0 Template [.vor] vor5 - StarDraw 5.0 Template (OpenOffice.org Impress) [.vor] wmf - Windows Metafile [.wmf] xhtml - XHTML [.xml] xpm - X PixMap [.xpm] The following list of spreadsheet formats are currently available: csv - Text CSV [.csv] dbf - dBASE [.dbf] dif - Data Interchange Format [.dif] fods - OpenDocument Spreadsheet (Flat XML) [.fods] html - HTML Document (OpenOffice.org Calc) [.html] ods - ODF Spreadsheet [.ods] ooxml - Microsoft Excel 2003 XML [.xml] ots - ODF Spreadsheet Template [.ots] pdf - Portable Document Format [.pdf] pxl - Pocket Excel [.pxl] sdc - StarCalc 5.0 [.sdc] sdc4 - StarCalc 4.0 [.sdc] sdc3 - StarCalc 3.0 [.sdc] slk - SYLK [.slk] stc - OpenOffice.org 1.0 Spreadsheet Template [.stc] sxc - OpenOffice.org 1.0 Spreadsheet [.sxc] uos - Unified Office Format spreadsheet [.uos] vor3 - StarCalc 3.0 Template [.vor] vor4 - StarCalc 4.0 Template [.vor] vor - StarCalc 5.0 Template [.vor] xhtml - XHTML [.xhtml] xls - Microsoft Excel 97/2000/XP [.xls] xls5 - Microsoft Excel 5.0 [.xls] xls95 - Microsoft Excel 95 [.xls] xlt - Microsoft Excel 97/2000/XP Template [.xlt] xlt5 - Microsoft Excel 5.0 Template [.xlt] xlt95 - Microsoft Excel 95 Template [.xlt] xlsx - Microsoft Excel 2007/2010 XML [.xlsx]
使用命令行前端:
$ bin/pp-unoconv --help usage: pp-unoconv [-h] [-f pdf] [-o] [-a] [-s http://localhost:6543] [-t None] [-v] input_filename positional arguments: input_filename Source file to be converted optional arguments: -h, --help show this help message and exit -f pdf, --format pdf Output format (default=pdf) -o , --output Write converted file to custom filename -s http://localhost:6543, --server-url http://localhost:6543 URL of Produce & Publish server) -t None, --authorization-token None Authorization token for P&P server -v, --verbose Verbose mode)
例如,可以使用以下命令行调用转换 my.docx 文档到HTML。转换结果将始终返回 作为包含转换数据的zip文件(在本例中为zip文件 将包含转换的HTML和提取的图形文件(如果适用)。 如果要访问托管转换,则需要专用的 标记 。 Zopyx有限公司提供的服务(联系我们):
bin/pp-unoconv -f html -s https://pp-server.zopyx.com -v -o out.zip -t <token> my.docx
任何python应用程序都可以通过 unconv() p p.client-python模块的api:
from pp.client.python.unoconv import unoconv def unoconv(input_filename, format='pdf', output='', server_url=None, authorization_token=None, verbose=False):
支持
目前仅支持生产和发布服务器及组件 以项目为基础。
许可证
p p.client-python 在GNU公共许可证v2(GPL 2)下发布。