开发者_Go百科
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionI have a MySQL table containing user submitted data.
I want the administrator to be able to click a button, and download all of the user data into an organized rich text format or pdf file, one user per page.
How do I do this?
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.
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.
PHPExcel library is worth your attention, also supports various formats
to generate a pdf file you should give a try to tcpdf.
http://www.tcpdf.org/
精彩评论