【问题标题】:PDF to HTML and HTML to PDF solution in phpphp中的PDF转HTML和HTML转PDF解决方案
【发布时间】:2016-01-26 06:34:58
【问题描述】:

我需要将 PDF 文档转换为 HTML 并在编辑 html 之后将此 HTML 转换为 PDF 。 我使用 'pdftohtml' ubuntu 命令(pdftohtml - 将 pdf 文件转换为 html、xml 和 png 图像的程序),如下面的 PHP 代码

<?php $output = shell_exec('pdftohtml create.pdf updated.html'); ?>

它成功地转换了整个文档,但它传递了页面顶部的所有图像。 谁能帮我做这个工作?

【问题讨论】:

  • 你考虑过选项 inline_css = true 吗?
  • @AbdelrahmanWahdan .. 感谢您的友好回复.. 我怎样才能使 inline_css = true ?我是否将其添加到 shell_exec() 中; ??

标签: php html pdf html-to-pdf pdf-to-html


【解决方案1】:
  • 您可以使用“-layout”标志将原始PDF 文件中的文档布局(页眉、页脚、分页等)保留在转换后的html 文件中。

    $output = shell_exec('pdftohtml -layout create.pdf updated.html');
    
  • 如果您只想转换 PDF 文件中的一系列页面,请使用“-f”和“-l”(小写“L”)标志来指定范围内的第一页和最后一页想要转换。

    $output = shell_exec('pdftohtml -f 5 -l 9 create.pdf updated.html');
    
  • 要转换使用所有者密码保护和加密的PDF 文件,请使用“-opw”标志(标志中的第一个字符是小写字母“O”,而不是零)。

    $output = shell_exec('pdftohtml -opw ‘password’ create.pdf updated.html');
    

Source

【讨论】:

  • 我做了你提到的一切......你的代码完美无缺,但我担心的是,当我转换 PDF 时,它会将 PDF 的所有图像移动到 html 标签的顶部......我该如何防止它??
  • 您到底使用了哪个PHP 库?我一直在使用这个,它工作得很好:github.com/mgufrone/pdf-to-html
  • 好的,我应用了您提到的库...它也成功转换了它,但我的问题是图像..图像转到顶部...这里是我的 PDF 屏幕截图:pdf...之后转换 HTML 截图:html
  • 好吧,我希望看到HTML页面而不是PDF文件的截图,因为你提到这个问题发生在转换后的HTML页面。
  • OK 这是HTML代码截图HTML screenshot
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多