如何使用 MySQL 表中的数据制作 RTF 格式或 PDF 文件?

发布于 2024-10-06 10:09:25 字数 1436 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲凉≈ 2024-10-13 10:09:25

在富文本格式 (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.

掩耳倾听 2024-10-13 10:09:25

我知道这个问题已经得到解答,但我最近遇到了这个问题,有几个问题,但没有不涉及某些第三方库或其他软件的答案 - 这是我的解决方案。

只需使用文本编辑器(例如 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();

我不确定是否可以将相同类型的技术用于 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:

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

音栖息无 2024-10-13 10:09:25

PHPExcel库值得你关注,也支持各种格式

PHPExcel library is worth your attention, also supports various formats

蓝海 2024-10-13 10:09:25

要生成 pdf 文件,您应该尝试 tcpdf。

http://www.tcpdf.org/

to generate a pdf file you should give a try to tcpdf.

http://www.tcpdf.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文