Between Rich Text Format (rtf) and pdf, I urge you to lean towards RTF.
Reason: it's editable. Just open it in MS Word (or many other editors) and your client is able to add headers, footers, emphasize some of the data, easily copy into a longer document etc etc.
I generate "wordy" reports for my clients in RTF and they think it's great.
PDF is designed to be printed. Period. So while it is possible to re-purpose a PDF doc, it will always be easier to do so from an RTF doc.
There are some PHP libraries available. Or you can generate it from scratch yourself. Example and example.
In addition the software, I recommend the guide by Sean Burke.
只需使用文本编辑器(例如 MS Word 或记事本或 Mac 上的 TextEdit)创建模板 RTF 文档,然后使用 PHP 的 str_replace() 函数来放入您想要的内容。
示例:
//load the rtf template as a string
$rtf = file_get_contents('mytemplate.rtf');
//replace placeholder text with content from database
$rtf = str_replace('content', 'here is my rtf content!', $rtf);
//and now serve the file as an rtf download:
Header("Content-type: application/rtf");
Header("Content-Disposition: attachment;filename=rtf.rtf");
echo $rtf;
exit();
I know this is answered but I came up against this problem recently and there are a few questions on it but no answers that don't involve some third party lib or other software - here's my solution.
Simply create a template RTF document using a text editor such as MS Word or Notepad or TextEdit on Mac, and use PHP's str_replace() function to drop in the content you want.
Example:
//load the rtf template as a string
$rtf = file_get_contents('mytemplate.rtf');
//replace placeholder text with content from database
$rtf = str_replace('content', 'here is my rtf content!', $rtf);
//and now serve the file as an rtf download:
Header("Content-type: application/rtf");
Header("Content-Disposition: attachment;filename=rtf.rtf");
echo $rtf;
exit();
I'm not sure if the same kind of technique could be used for PDFs but this saved me plenty of headaches in the past, especially when trying to use rather badly documented PHP / RTF converter classes or looking at solutions which involve being able to install software on a server or run a command from the shell.
I've also used PHPRTFLite before,but found it far too complex to perform simple tasks and too vaguely documented to be of much help.
发布评论
评论(4)
在富文本格式 (rtf) 和 pdf 之间,我强烈建议您倾向于 RTF。
原因:可编辑。只需在 MS Word(或许多其他编辑器)中打开它,您的客户就可以添加页眉、页脚、强调某些数据、轻松复制到更长的文档等。
我为客户生成 RTF 格式的“冗长”报告,他们认为这很棒。
PDF 设计用于打印。时期。因此,虽然可以重新调整 PDF 文档的用途,但从 RTF 文档中进行此操作总是更容易。
有一些 PHP 库可用。或者您可以自己从头开始生成它。 示例 和 示例。
除了软件之外,我还推荐 Sean Burke 的指南。
Between Rich Text Format (rtf) and pdf, I urge you to lean towards RTF.
Reason: it's editable. Just open it in MS Word (or many other editors) and your client is able to add headers, footers, emphasize some of the data, easily copy into a longer document etc etc.
I generate "wordy" reports for my clients in RTF and they think it's great.
PDF is designed to be printed. Period. So while it is possible to re-purpose a PDF doc, it will always be easier to do so from an RTF doc.
There are some PHP libraries available. Or you can generate it from scratch yourself. Example and example.
In addition the software, I recommend the guide by Sean Burke.
我知道这个问题已经得到解答,但我最近遇到了这个问题,有几个问题,但没有不涉及某些第三方库或其他软件的答案 - 这是我的解决方案。
只需使用文本编辑器(例如 MS Word 或记事本或 Mac 上的 TextEdit)创建模板 RTF 文档,然后使用 PHP 的 str_replace() 函数来放入您想要的内容。
示例:
我不确定是否可以将相同类型的技术用于 PDF,但这在过去为我省去了很多麻烦,尤其是在尝试使用文档记录相当糟糕的 PHP / RTF 转换器类或寻找涉及能够的解决方案时在服务器上安装软件或从 shell 运行命令。
我之前也使用过 PHPRTFLite ,但发现它太复杂了,无法执行简单的操作任务和记录太模糊,没有多大帮助。
I know this is answered but I came up against this problem recently and there are a few questions on it but no answers that don't involve some third party lib or other software - here's my solution.
Simply create a template RTF document using a text editor such as MS Word or Notepad or TextEdit on Mac, and use PHP's str_replace() function to drop in the content you want.
Example:
I'm not sure if the same kind of technique could be used for PDFs but this saved me plenty of headaches in the past, especially when trying to use rather badly documented PHP / RTF converter classes or looking at solutions which involve being able to install software on a server or run a command from the shell.
I've also used PHPRTFLite before,but found it far too complex to perform simple tasks and too vaguely documented to be of much help.
PHPExcel库值得你关注,也支持各种格式
PHPExcel library is worth your attention, also supports various formats
要生成 pdf 文件,您应该尝试 tcpdf。
http://www.tcpdf.org/
to generate a pdf file you should give a try to tcpdf.
http://www.tcpdf.org/