有人遇到过将文本或文档转换为 pdf 的 php 代码吗?
它必须遵循与原始 txt 或 doc 文件相同的格式,意味着换行和新段落...
最佳答案
可以使用 phpLiveDocx 将 DOC 转换为 PDF :
$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);
对于文本到 PDF,您可以使用 pdf extension是PHP。 您可以查看示例 here .
关于php - 使用 php 将 txt 或 doc 转换为 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2348835/