Forum Moderators: coopster

Message Too Old, No Replies

On-the-fly printable document creation w/ PHP

pdflib, or alternatives to create .doc or .rtf

         

louponne

10:06 am on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to create a series of printable documents server-side. A few factors:
Of a given 5-page document, only the first page will actually have any dynamic content at all. The rest is static.
Althought the layout isn't horribly complex, both the dynamic content and the static has some texts organized in tables.
The dynamic content consists of a series of fields - name, address, etc.

I've used fpdf for some really simple server-side pdf creation, but this is going to need something more robust.

Can anyone with exerpience with doing this give me some idea of how complex this will be? Advantages to using rtf or pdf?

Many thanks for all input!

vincevincevince

11:14 pm on Jul 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the pdf libraries are not free for commerical uses :-(

louponne

6:38 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone have any experience producing .rtf on-the-fly? How difficult is it? Can I set up tables of info/text?

vincevincevince

12:56 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was too lazy to study rtf codes, so I used microsoft word, put in %fielda% %fieldb% etc codes, saved as .rtf, then used str_replace("%fielda%",$fielda,$rtf_file);

if you follow my meaning? that worked really well actually :-) I could do all the pretty formatting that words allows, then add on dynamic content generation/addition - and what's more it left it in a very commonly readable format (rtf), which could be edited by the end user using MS Word :-)

louponne

3:14 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanksthanksthanks, vincevincevince!

What you're describing is a perfect solution to what I need to do! So as I understand it, you can do all the fancy page layout (well, not *that* fancy) in Word, and then just dig open the file up dynamically and change the few values and then serve it up?

Sounds great.

vincevincevince

6:12 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yep, that's what i do, a few helpful snippets:


//load the rtf
$source = fopen("source.rtf", "r");
$text = fread($source, fileSize("source.rtf"));
fclose($source);

//quick function for filling in values
function fillin($field,$value,$thetext)
{
return preg_replace("/[\$]$field/",$value,$thetext);
}

//use the function as many times as needed
$text=fillin("client_name",$client_name,$text);

//output the rtf again
header("HTTP/1.1 200 OK");
header("Content-type: application/rtf");
header("Content-length: ".strlen($text));
print ($text);

note the above fillin function is designed for where you have put in the original rtf document fields denoted by $, e.g. $client_name

louponne

7:01 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again vincevincevince!
Terrific! :)

killroy

2:57 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just reminded me of something I did using the same technique, which I foudn very usefull.

I had a few small rounded corner gifs, and was experimenting with colour schemes. So I saved a few copies with different colours, opened the files (only around 100 or so byteS) checked where the color was, jsut a 3 byte bit, and then used s ingle image and dynamically changed colours to fit the CSS colours settings.

SN

louponne

12:40 pm on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are the methods for generating .rtf files server-side? Is it complicated?

louponne

4:34 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The more I thought about it, the more it occured to me that .rtf was the way to do.
Many thanks to hakre for the threads - I certainly have enough reading now to get going! (and thanks again vincevincevince for your input on the other thread!)

[edited by: jatar_k at 5:23 pm (utc) on July 14, 2003]