简体   繁体   中英

RTF Library - PHPrtf Has anyone used it?

For some reason, my line breaks in my test.txt file are not being preserved.

$sect->writeText(file_get_contents("test.txt"), $times12, $null);

Has anyone played around with this library?

http://sourceforge.net/projects/phprtf/

My question is: How can I preserve my line breaks from my test.txt file? What is happening is the document is just merging all the text together without the line breaks.

Any ideas? You would probably have to have experience with this library..

Looking at the source for PHPrtf it looks like the author has forgotten to include regular line breaks. They've included DOS style line endings, "\\r\\n", which creates an RTF paragraph (\\par), but nothing which creates an RTF linebreak (\\line).

You have 2 options, replace your (I presume nix) line endings in the output from get_file_contents() with \\r\\n's, to create paragraphs in the RTF, eg:

str_replace("\n", "\r\n", $text);

Or you can patch rtf/Container.php, specifically inserting the following at the top of "Container::writeText()":

$text = str_replace("\n", "\n".'\line ', $text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM