在PHP中将PDF转换为HTML和HTML转换为PDF解决方案 [英] PDF to HTML and HTML to PDF solution in php

查看:4842
本文介绍了在PHP中将PDF转换为HTML和HTML转换为PDF解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

成功转换整个文档,但它将页面顶部的所有图像传递给它。
任何人都可以帮我完成这项工作吗?

解决方案


  • 保留已转换的 html 中原始 PDF 文件的文档布局(页眉,页脚,分页等) >文件使用-layout标志。

      $ 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'); 




来源

I need to convert a PDF document to HTML and after editing the html I then convert this HTML to PDF . I use 'pdftohtml' ubuntu command (pdftohtml - program to convert pdf files into html, xml and png images) like PHP code below

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

It convert the whole document successfully but it pass all image in top of the page. Can anyone help me to do this job ?

解决方案

  • You can preserve the layout of your document (headers, footers, paging, etc.) from the original PDF file in the converted html file using the "-layout" flag.

    $output = shell_exec('pdftohtml -layout create.pdf updated.html');
    

  • If you want to only convert a range of pages in a PDF file, use the "-f" and "-l" (a lowercase "L") flags to specify the first and last pages in the range you want to convert.

    $output = shell_exec('pdftohtml -f 5 -l 9 create.pdf updated.html');
    

  • To convert a PDF file that’s protected and encrypted with an owner password, use the "-opw" flag (the first character in the flag is a lowercase letter "O", not a zero).

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

Source

这篇关于在PHP中将PDF转换为HTML和HTML转换为PDF解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆