3

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

redcoder
  • 97
  • 1
  • 2
  • 8
  • or has anyone come across using FPDF that convert txt to pdf ? I am stuck at reading file from txt file and put them into the same paragraph or carriage line as it is and convert into pdf using FPDF – redcoder Feb 27 '10 at 20:36
  • let say I have a list of txt files and they could be inside a subdirectories example folder1/abc.txt ,folder1/pqr.txt , folder1/folder2/def.txt etc.... I am looking to write a code that automatically read those txt files and convert it into pdf..but they got to have the same paragraphing as the oiriginal txt file.. – redcoder Feb 27 '10 at 20:40

4 Answers4

4

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
  • 8,009
  • 3
  • 26
  • 25
  • H iSagi, thanks for your example, unfortunately I don't use Zend framework on the server – redcoder Feb 27 '10 at 20:35
  • 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 Feb 27 '10 at 20:39
  • Using this service, is it possible to convert a word document into pdf on the fly? – shasi kanth Aug 12 '11 at 07:41
1

See HTML_ToPDF. It also works for text.

Andrei Cristian Prodan
  • 1,114
  • 4
  • 17
  • 34
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

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

Community
  • 1
  • 1
extraneon
  • 23,575
  • 2
  • 47
  • 51
0

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.

Jeroen Ritmeijer
  • 2,772
  • 3
  • 24
  • 31