php convert word pdf,php – 命令`libreoffice –headless –convert-to pdf test.docx –outdir/pdf`不工作...
>我会首先尝试给绝对路径命令。
>我怀疑libreoffice二进制不工作 – 你必须找到soffice二进制,看看是否工作。
>然后,你的–convert-到pdf是不够的。它需要:
--convert-to pdf:writer_pdf_Export
一定要遵循这个大小写!
>接下来,如果您的系统上已经启动并运行了一个LibreOffice GUI实例,该命令将不会工作。它是由bug known since 2011引起的。将此附加参数添加到命令中:
"-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"
这将创建一个新的,单独的环境,其可以由第二个无头LO实例使用,而不干扰由相同用户启动的可能运行的第一GUI LO实例。
>另外,请确保您指定的–outdir / pdf确实存在,并且您具有写入权限。或者,使用不同的输出dir。即使它只是第一次测试和这个调试回合:
$ mkdir ${HOME}/lo_pdfs
>因此:
/path/to/soffice \
--headless \
"-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" \
--convert-to pdf:writer_pdf_Export \
--outdir ${HOME}/lo_pdfs \
/path/to/test.docx
这对我来说在Mac OS X Mavericks 10.9.5与LibreOffice v4.4.3.2(使用我的特定路径的二进制soffice,这将是不同的你反正…)。
如果所有这些都不起作用:
>这可能是一个问题,具体的DOCX文件您尝试命令与…所以创建一个非常简单的DOCX文档您自己的第一。使用LibreOffice本身。写“Hello World!”在其他空页面上。将其另存为DOCX。
>再试一次。它与简单的DOCX工作吗?
>如果它再次不工作,重复步骤7,但此时保存为ODT。
>重复步骤8,但请确保此时引用ODT。
> Last:使用soffice的完整路径,soffice.bin和libreoffice,并使用-h参数运行每个:
$ /path/to/libreoffice -h
$ /path/to/soffice -h
$ /path/to/soffice.bin -h
>你甚至得到一个输出吗?
>对于三个二进制文件/符号链接中的哪一个?
>记录输出。
>告诉我们你的输出!
将它们与您使用的命令行进行比较:
Are there any changes in parameter names, capitalizations, number of dashes used, etc.??
为了比较,我自己的输出在这里:
$ /Applications/LibreOffice.app/Contents/MacOS/soffice -h
LibreOffice 4.4.3.2 88805f81e9fe61362df02b9941de8e38a9b5fd16
Usage: soffice [options] [documents...]
Options:
--minimized keep startup bitmap minimized.
--invisible no startup screen, no default document and no UI.
--norestore suppress restart/restore after fatal errors.
--quickstart starts the quickstart service
--nologo don't show startup screen.
--nolockcheck don't check for remote instances using the installation
--nodefault don't start with an empty document
--headless like invisible but no userinteraction at all.
--help/-h/-? show this message and exit.
--version display the version information.
--writer create new text document.
--calc create new spreadsheet document.
--draw create new drawing.
--impress create new presentation.
--base create new database.
--math create new formula.
--global create new global document.
--web create new HTML document.
-o open documents regardless whether they are templates or not.
-n always open documents as new files (use as template).
--display
Specify X-Display to use in Unix/X11 versions.
-p
print the specified documents on the default printer.
--pt
print the specified documents on the specified printer.
--view
open the specified documents in viewer-(readonly-)mode.
--show
open the specified presentation and start it immediately
--accept=
Specify an UNO connect-string to create an UNO acceptor through which
other programs can connect to access the API
--unaccept=
Close an acceptor that was created with --accept=
Use --unnaccept=all to close all open acceptors
--infilter=[:filter_options]
Force an input filter type if possible
Eg. --infilter="Calc Office Open XML"
--infilter="Text (encoded):UTF8,LF,,,"
--convert-to output_file_extension[:output_filter_name[:output_filter_options]] [--outdir output_dir] files
Batch convert files.
If --outdir is not specified then current working dir is used as output_dir.
Eg. --convert-to pdf *.doc
--convert-to pdf:writer_pdf_Export --outdir /home/user *.doc
--convert-to "html:XHTML Writer File:UTF8" *.doc
--convert-to "txt:Text (encoded):UTF8" *.doc
--print-to-file [-printer-name printer_name] [--outdir output_dir] files
Batch print files to file.
If --outdir is not specified then current working dir is used as output_dir.
Eg. --print-to-file *.doc
--print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc
--cat files
Dump text content of the files to console
Eg. --cat *.odt
--pidfile file
Store soffice.bin pid to file.
-env:[=]
Set a bootstrap variable.
Eg. -env:UserInstallation=file:///tmp/test to set a non-default user profile path.
Remaining arguments will be treated as filenames or URLs of documents to open.
>向命令行添加一个参数,以在soffice打开DOCX文件时强制应用输入过滤器:
--infilter="Microsoft Word 2007/2010/2013 XML"
要么
--infilter="Microsoft Word 2007/2010/2013 XML"
--infilter="Microsoft Word 2007-2013 XML"
--infilter="Microsoft Word 2007-2013 XML Template"
--infilter="Microsoft Word 95 Template"
--infilter="MS Word 95 Vorlage"
--infilter="Microsoft Word 97/2000/XP Template"
--infilter="MS Word 97 Vorlage"
--infilter="Microsoft Word 2003 XML"
--infilter="MS Word 2003 XML"
--infilter="Microsoft Word 2007 XML Template"
--infilter="MS Word 2007 XML Template"
--infilter="Microsoft Word 6.0"
--infilter="MS WinWord 6.0"
--infilter="Microsoft Word 95"
--infilter="MS Word 95"
--infilter="Microsoft Word 97/2000/XP"
--infilter="MS Word 97"
--infilter="Microsoft Word 2007 XML"
--infilter="MS Word 2007 XML"
--infilter="Microsoft WinWord 5"
--infilter="MS WinWord 5"
更新
LibreOffice不仅可以在命令行上将DOCX转换为PDF:
>它可以处理任何可以打开和“读取”的输入格式:DOC,XLS,XLSX,PPT,PPTX,…
>它可以转换为任何输出格式,它可以“写”:DOC,XLS,XLSX,PPT,PPTX,…
当然,结果永远不会是完美的,有时他们甚至是你不能接受的。
回覆。输出为PDF:
要控制哪个LibreOffice组件生成PDF输出,您可以使用以下变量:
--convert-to pdf:writer_pdf_Export
--convert-to pdf:calc_pdf_Export
--convert-to pdf:draw_pdf_Export
--convert-to pdf:impress_pdf_Export
--convert-to pdf:writer_web_pdf_Export
回覆。输入不是DOCX:
要对非DOCX输入格式强制使用infilter,您可以使用(列表不完整):
--infilter="HTML Document" # for HTML input
--infilter="MediaWiki" # for MediaWiki input
--infilter="Text CSV" # for CSV spreadsheet input
--infilter="Microsoft PowerPoint 2007/2010 XML" # for PPTX input
--infilter="Microsoft PowerPoint 97/2000/XP" # for PPT input
--infilter="Windows Metafile" # for WMF input
--infilter="Enhanced Metafile" # for EMF input
--infilter="Scalable Vector Graphics" # for SVG input
--infilter="Microsoft Excel 2007/2010 XML" # for XLSX input
--infilter="Microsoft Excel 97/2000/XP" # for XLS input
--infilter="Microsoft Excel 95" # for some XLS input
--infilter="Microsoft Excel 5.0" # for some XLS input
回覆。输出不是PDF:
要转换为特定的输出格式,您可以使用(列表不完整):
--convert-to html:HTML
--convert-to html:draw_html_Export # force "Draw" to generate the HTML
--convert-to mediawiki:MediaWiki_Web # generate MediaWiki output
--convert-to csv:"Text - txt - csv (StarCalc)" # generate CSV spreadsheet output
--convert-to pptx:"Impress MS PowerPoint 2007 XML" # generate PPTX
--convert-to ppt:"MS PowerPoint 97" # generate PPT
--convert-to wmf:impress_wmf_Export # force "Impress" to generate the WMF
--convert-to wmf:draw_wmf_Export # force "Draw" to generate the WMF
--convert-to emf:impress_emf_Export # force "Impress" to generate the EMF
--convert-to emf:draw_emf_Export # force "Draw" to generate the EMF
--convert-to svg:impress_svg_Export # force "Impress" to generate the SVG
--convert-to svg:draw_svg_Export # force "Draw" to generate the SVG
--convert-to xlsx:"Calc MS Excel 2007 XML" # generate XLSX
--convert-to xls:"MS Excel 97" # generate XLS like Excel 97
--convert-to xls:"MS Excel 95" # generate XLS like Excel 95
--convert-to xls:"MS Excel 5.0/95" # generate XLS like Excel 5.0/95
更多推荐



所有评论(0)