Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High-quality PDF to Word conversion in PHP?

Tags:

php

ms-word

pdf

What's the best way of converting PDF docs to Microsoft Word format in PHP? This can be either as a PHP script or calling a (Linux) executable (with proc_open()). It just needs to be relatively fast and produce quality Word documents (in 97/2000/2003 format).

Commercial software is OK.

like image 567
cletus Avatar asked Jan 13 '09 01:01

cletus


1 Answers

To read PDF files, you will need to install the XPDF package, which includes "pdftotext." Once you have XPDF/pdftotext installed, you run the following PHP statement to get the PDF text:

content = shell_exec('/usr/local/bin/pdftotext '.$filename.' -');

After getting the content, Download PHPDOCX Community version, try like this.

<?php
require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();
$textInfo = $content;

$paramsTextInfo = array(
    'val' => 1,
    'i' => 'single',
    'sz' => 8
);

$docx->addText($textInfo, $paramsTextInfo);

$docx->createDocx('report.docx');
?>
like image 168
Shankar Narayana Damodaran Avatar answered Nov 19 '22 08:11

Shankar Narayana Damodaran