Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert txt or doc to pdf using php [duplicate]

Tags:

php

pdf

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...

like image 839
redcoder Avatar asked Sep 15 '25 20:09

redcoder


2 Answers

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.

like image 62
Sagi Avatar answered Sep 19 '25 10:09

Sagi


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 :)

like image 44
extraneon Avatar answered Sep 19 '25 12:09

extraneon