jjzjj

libreoffice - 命令 `libreoffice --headless --convert-to pdf test.docx --outdir/pdf` 不工作

coder 2023-06-12 原文

在使用这个旨在将 DOCX 转换为 PDF 的 LibreOffice 命令后,我必须等待很长时间:

libreoffice --headless --convert-to pdf test.docx --outdir  /pdf

但我没有得到任何回应,也没有错误。没有文件被转换。看起来终端挂了。

那么,有什么方法可以跟踪错误吗?

最佳答案

  1. 我会首先尝试为命令提供绝对路径。

  2. 我怀疑 libreoffice 二进制文件不起作用——您必须找到 soffice 二进制文件并查看它是否有效。

  3. 那么,您的 --convert-to pdf 是不够的。它必须是:

    --convert-to pdf:writer_pdf_Export
    

    一定要严格遵守这个大写字母!

  4. 接下来,如果您的系统上已经启动并运行了 LibreOffice GUI 实例,则该命令将不起作用。这是由错误引起的 known since 2011 .将此附加参数添加到您的命令中:

     "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"
    

    这将创建一个新的独立环境,可供第二个 headless LO 实例使用,而不会干扰由同一用户启动的可能正在运行的第一个 GUI LO 实例。

  5. 此外,请确保您指定的 --outdir/pdf 确实存在,并且您有写入权限。或者,而是使用不同的输出目录。即使只是第一次测试和这一轮调试:

    $ mkdir ${HOME}/lo_pdfs
    
  6. 因此:

    /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 的特定路径,无论如何这对你来说都是不同的...)。

    如果这一切都不起作用:

  7. 您尝试使用命令的特定 DOCX 文件可能有问题...因此,请先创建一个您自己的非常简单的 DOCX 文档。为此使用 LibreOffice 本身。写“ Hello World !”在一个空白的页面上。将其保存为 DOCX。

  8. 再试一次。 它适用于简单的 DOCX 吗?

  9. 如果还是不行,重复第 7 步,但这次另存为 ODT。

  10. 重复第 8 步,但确保这次引用 ODT。

  11. 最后:使用 sofficesoffice.binlibreoffice 的完整路径,并使用 运行每个-h 参数:

    $ /path/to/libreoffice -h
    $ /path/to/soffice -h
    $ /path/to/soffice.bin -h
    
    • 你甚至在这里得到输出吗?
    • 对于三个二进制文件/符号链接(symbolic link)中的哪一个?
    • 记录输出。
    • 告诉我们您的输出!!!

    将它们与您使用的命令行进行比较:

    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 <display>
            Specify X-Display to use in Unix/X11 versions.
      -p <documents...>
            print the specified documents on the default printer.
      --pt <printer> <documents...>
            print the specified documents on the specified printer.
      --view <documents...>
            open the specified documents in viewer-(readonly-)mode.
      --show <presentation>
            open the specified presentation and start it immediately
      --accept=<accept-string>
            Specify an UNO connect-string to create an UNO acceptor through which
            other programs can connect to access the API
      --unaccept=<accept-string>
            Close an acceptor that was created with --accept=<accept-string>
            Use --unnaccept=all to close all open acceptors
      --infilter=<filter>[: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:<VAR>[=<VALUE>]
            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.
    
  12. 在命令行中再添加一个参数,以在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="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

关于libreoffice - 命令 `libreoffice --headless --convert-to pdf test.docx --outdir/pdf` 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30349542/

有关libreoffice - 命令 `libreoffice --headless --convert-to pdf test.docx --outdir/pdf` 不工作的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  4. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  5. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

  6. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  7. ruby-on-rails - Prawn PDF : I need to generate nested tables - 2

    我需要一个表,其中行实际上是2行表,一个嵌套表是..我怎样才能在Prawn中做到这一点?也许我需要延期..但哪一个? 最佳答案 现在支持子表:Prawn::Document.generate("subtable.pdf")do|pdf|subtable=pdf.make_table([["sub"],["table"]])pdf.table([[subtable,"original"]])end 关于ruby-on-rails-PrawnPDF:Ineedtogeneratenested

  8. ruby - JetBrains RubyMine 3.2.4 调试器不工作 - 2

    使用Ruby1.9.2运行IDE提示说需要gemruby​​-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall

  9. ruby - `rescue $!` 是如何工作的? - 2

    我知道全局变量$!包含最新的异常对象,但我对下面的语法感到困惑。谁能帮助我理解以下语法?rescue$! 最佳答案 此构造可防止异常停止您的程序并使堆栈跟踪冒泡。它还会将该异常作为值返回,这很有用。a=get_me_datarescue$!在此行之后,a将保存请求的数据或异常。然后您可以分析该异常并采取相应措施。defget_me_dataraise'Nodataforyou'enda=get_me_datarescue$!puts"Executioncarrieson"pa#>>Executioncarrieson#>>#更现实的

  10. ruby-on-rails - rbenv:从 RVM 移动到 rbenv 后,在 Jenkins 执行 shell 中找不到命令 - 2

    我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions

随机推荐