-->

PDF to HTML and HTML to PDF solution in php

2019-08-09 22:50发布

问题:

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 ?

回答1:

  • 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