tags:

views:

468

answers:

4

have anyone come across a php code that convert text or doc into pdf ?

it has to follow the same format as the original txt or doc file meaning the line feed as well as new paragraph...

+2  A: 

Converting from DOC to PDF is possible using phpLiveDocx:

$phpLiveDocx = new Zend_Service_LiveDocx_MailMerge();
$phpLiveDocx->setUsername('username')
            ->setPassword('password');
$phpLiveDocx->setLocalTemplate('document.doc');
// necessary as of LiveDocx 1.2
$phpLiveDocx->assign('dummyFieldName', 'dummyFieldValue');
$phpLiveDocx->createDocument();
$document = $phpLiveDocx->retrieveDocument('pdf');
file_put_contents('document.pdf', $document);
unset($phpLiveDocx);

For text to PDF, you can use the pdf extension is PHP. You can view the examples here.

Sagi
H iSagi, thanks for your example, unfortunately I don't use Zend framework on the server
redcoder
In my experience this is the best tool without using COM in windows server. You don't have to use Zend framework. You do have, however, to download it as some components are required for LiveDocx.
Sagi
+1  A: 

See HTML_ToPDF. It also works for text. Also see word to pdf using php.

Sarfraz
A: 

Have a look at this SO question. Using OpenOffice in command line mode for conversions can be done, though you'd have to search a bit for the conversion macro's. I'm not saying it's light-weight though :)

extraneon
A: 

It has been a long time since I touched PHP, but if you can make web service calls from it then try this product. It provides excellent conversion fidelity. It also supports additional formats including Infopath, Excel, PowerPoint etc as well as Watermarking support.

Please note that I have worked on this product so the usual disclaimers apply.

Muhimbi