且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP中将PDF转换为HTML和HTML转换为PDF解决方案

更新时间:2023-01-23 10:59:20


  • 保留已转换的 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