PHP Classes

File: examples/

Recommend this page to a friend!
  Classes of Christian Vigh   PHP RTF Tools   examples/   Download  
File: examples/
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP RTF Tools
Parse and generate RTF documents using templates
Author: By
Last change: Initial version
Date: 7 years ago
Size: 2,730 bytes


Class file image Download


To run the examples, simply follow the instructions below.

Example script : beautify/beautify.php

This sample scripts simply beautifies the contents of file sample.rtf and echo them on standard output.

Example script : beautify/beautify_perf.php

This script tries, apart from beautifying sample files, tries to do a performance comparison between the RtfStringBeautifier and RtfFileBeautifier classes.

It also tests the performances of the RtfFileBeautifier class on a file which should be too large to fit into memory.

Generating the sample files

The sample file, used by the by the create\_sample.php script described above, contains the first two pages of the latest Rtf format specification from Microsoft, which you can download here :

The create\_sample.php file will allow you to create two files, generated by simply catenating several times the sample.rtf file :

  • bigfile.rtf, which should be around 43Mb
  • verybigfile.rtf, which should readh more than 860Mb, a size too big to fit into memory.

Running the script

The beautify.php script generates 3 files :

  • bigfile.string.txt, the beautified contents of bigfile.rtf using the RtfStringBeautifier class
  • bigfile.file.txt, the beautified contents of bigfile.rtf using the RtfFileBeautifier class
  • verybigfile.txt, the beautified contents of verybigfile.rtf using the RtfFileBeautifier class (the RtfStringBeautifier class won't be used on this file since it's too large to fit into memory)

The contents of bigfile.string.txt and bigfile.file.txt must be the same.

Don't be surprised if the contents of the beautified files are shorter than their original version : this is because we use here the default beautifying options, which include the BEAUTIFY\_STRIP\_IMAGE_DATA ; therefore, image contents are stripped from the output and replaced with a comment saying : "/x bytes of image data not shown/".

Example script : texter/texter.php

This script echoes on its standard output the contents of file sample.rtf, located in the same directory.

Example script : templater/templater.php

This script echoes on its standard output the contents of file sample.rtf, located in the same directory, with all the templating instructions evaluated.

Example script : merger/merger.php

This script saves in file output.rtf the merged contents of files sample1.rtf through sample4.rtf.