About RTF Generator - Basic Edition

About RTF Generator – Basic Edition

RTF Generator

The main purpose of the script is generating (not parsing) RTF files. It consists in a PHP class and it is based on Rich Text Format (RTF) Specification Version 1.7 as is published by Microsoft Corporation.

Basic Edition

The Basic Edition of this script is freeware and contains only a light set of functions. If you need more for yours applications please consider the Standard or Professional Edition, which can offers you a total control of the RTF file.

What is the RTF ?

The rich-text format (RTF) standard is a method of encoding formatted text and graphics for easy transfer between different programs and different operations.

The RTF Specification provides a format for text and graphics interchange that can be used with different output devices, operating environments, and operating systems. Generally, it is used by all Microsoft Word programs — Word for Windows, Word for the Macintosh, and Word for MS-DOS — for moving word-processing documents between different platforms without having to rely on special translation software or conversion utilities. RTF uses the ANSI, PC-8, Macintosh, or IBM PC character set to control the representation and formatting of a document, both on the screen and in print. With the RTF Specification, documents created under different operating systems and with different software applications can be transferred between those operating systems and applications.

RTF version 1.7 includes all new control words introduced by Microsoft Word for Windows 95 version 7.0, Word 97 for Windows, Word 98 for the Macintosh, Word 2000 for Windows, and Word 2002 for Windows, as well as other Microsoft products.

Technical information

The RTF Generator is written in PHP, in fact it is a PHP class who uses no additional components. It could be easily installed and used to create documents you need. The script was developed in PHP 4.3.0 running as a module in Apache 1.3.14.


Installing the RTF Generator

What the package contains?

The RTFGen V 1.0 – Basic Edition contains the following files :

  • “frtf.php” which is the main file containing the PHP class
  • “param.inc.php” which is used to configure the class
  • “rtfkeywords.inc.php” which contains all the keywords defined by RTF Specification V 1.7

Installing the script

In order to install the script all you have to do is to unzip the archive in the directory at your choice.


Methods

Index of methods

  1. FRTF

  2. Open

  3. Close

  4. Output

  5. SetWindowCaption

  6. SetPageOrientation

  7. SetDocumentView

  8. SetViewKind

  9. SetViewScale

  10. SetViewZk

  11. SetPaperSize

  12. LastWordSupported

  13. Write


FRTF – the constructor

Signature

function FRTF  (  $Orientation = 'P',  $PageFormat = 'A4',  $Lang = 'EN'  )

Description

This is the constructor of the class.

Parameters

$Orientation – specify the orientation of the page Portrait/Landscape

Allowed values:

  • ‘L’,’l’ or anything that starts with ‘L’,‘l’ for Landscape
  • Anything else for Portrait

By default: 'Portrait'

$PageFormat – specify the size of the page

Allowed values:

  • Letter
  • Legal
  • Executive
  • A3
  • A4

By default : 'Letter'

$Lang – specify the language the error messages will be displayed in

Allowed values:

  • English | Engleza | En | E
  • Romanian | Romana | Ro | R
  • French | Franceza | Fr | F
  • Italian | Italiana | It | I
  • German | Germana | De | D

By default: 'English'


Open

Signature

function Open()

Description

This method begin the generation of the RTF file. It has to be called before any other method.

Parameters


Close

Signature

function Close ()

Description

This method will terminate the RTF document. It is not necessary to call it explicitly because the Output() method will do that for you.

Parameters


Output

Signature

function Output ( $File = '' )

Description

Send the RTF document to the browser or save it locally when the $File is present. This method begin by calling the Close() method if it is necessary.

Parameters

$File - the name of the file. If it is null the document will be sent to the browser who will use the plug-in if installed.


SetWindowCaption

Signature

function SetWindowCaption( $Caption = '' )

Description

This method sets the caption text for the document window.

Parameters

$Caption - the string to be displayed in the window caption.


SetPageOrientation

Signature

function SetPageOrientation( $Orientation = '' )

Description

This method set the page orientation for the RTF document. By default the page orientation is portrait and it is not necessary to call this method with the 'Portrait' parameter in order to specify it.

Parameters

$Orientation - specify the orientation of the page Portrait/Landscape

Allowed values:

  • ‘L’,’l’ or anything that starts with ‘L’,‘l’ for Landscape
  • Anything else for Portrait

By default: 'Portrait'


SetDocumentWindow

SetDocumentView

Signature

function SetDocumentView ( $Kind = '', $Scale = '', $Zoom = '' )

Description

This method set the view mode, the zoom level and the zoom kind of the document.

Parameters

$Kind - represents the view mode of the document.

Allowed values:

  • 'None'
  • 'Page Layout'
  • 'Outline'
  • 'Master Document' |' Master'
  • 'Normal'
  • 'Online Layout' | 'Online'

By default : 'None'

$Scale - zoom level of the document; the argument is a value representing a percentage (the default is 100).

$Zoom - represents the zoom kind of the document

Allowed values:

  • 'None'
  • 'Full Page' | 'Full' | 'Page'
  • 'Best Fit' | 'Best' | 'Fit'

By default : 'None'


SetViewKind

Signature

function SetViewKind( $ViewKind = '')

Description

This method set the view mode of the document.

Parameters

$ViewKind - represents the view mode of the document.

Allowed values:

  • 'None'
  • 'Page Layout'
  • 'Outline'
  • 'Master Document' |' Master'
  • 'Normal'
  • 'Online Layout' | 'Online'

By default : 'None


SetViewScale

Signature

function SetViewScale( $Scale = '' )

Description

This method set the zoom level of the document.

Parameters

$Scale - zoom level of the document; the argument is a value representing a percentage (the default is 100).


SetViewZk

Signature

function SetViewZk ( $ZoomKind = '')

Description

This method set the zoom kind of the document.

Parameters

$ZoomKind - represents the zoom kind of the document

Allowed values:

  • 'None'
  • 'Full Page' | 'Full' | 'Page'
  • 'Best Fit' | 'Best' | 'Fit'

By default : 'None'


SetPaperSize

Signature

function SetPaperSize ( $NewVal = '' )

Description

Define the size of the paper for the RTF document. The size can be specified by passing as parameter the paper format.

In the Basic Edition you can chose between five formats listed in the section bellow.

Parameters

$NewVal - the type of paper used for this document

Allowed values:

  • Letter
  • Legal
  • Executive
  • A3
  • A4

By default : 'Letter'


LastWordSupported

Signature

function LastWordSupported ()

Description

This method return a string with the version of the Microsoft Word who fully support all the keywords used in the current RTF document.

Parameters


Write

Signature

function Write( $Txt, $NewPar = 'Yes' )

Description

Write a text in the RTF document at the current position of the cursor.

In the Basic Edition you can not specify any formatting properties( like font properties, paragraph properties, border properties, frame properties, etc.) for the text.

Parameters

$Txt - the text to be written in the document

$NewPar - a flag specifying if the text will be written in a new paragraph.

Allowed values:

  • 'Yes' - that means a new paragraph will be emitted in order to write the text
  • 'No' - that means the text will be written continuously in the current paragraph

By default : 'Yes'


Samples for RTF Generator - Basic Edition

Samples for RTF Generator – Basic Edition

Sample 1

Sample 2

Sample 3


Sample 1

In order to create your first RTF document all you have to do is to write the following lines in your PHP file:

<?php
require('frtf.php');

$rtf=new FRTF();
$rtf->Open();
$rtf->Write('My
          first rtf document created with RTF Generator');
$rtf->Close();
$rtf->Output();
?>

and this is what you will obtain:


Sample 2

Write this in your PHP file:

<?php
require('frtf.php');

$rtf=new FRTF('Lansdcape','A4','en');
$rtf->Open();
$rtf->SetDocumentView('Page',100);
$rtf->Write("The
          first text to be diplayed");
$rtf->Write("This
          string will be displayed continously",'no');
$rtf->Write('Another
          string in a new paragraph');
$rtf->Close();
$rtf->Output();
?>

or this

<?php
require('frtf.php');

$rtf=new FRTF();
$rtf->Open();
$rtf->SetPaperSize('A4');
$rtf->SetPageOrientation('L');
$rtf->SetDocumentView('Page',100);
$rtf->Write("The
          first text to be diplayed");
$rtf->Write("This
          string will be displayed continously",'no');
$rtf->Write('Another
          string in a new paragraph');
$rtf->Close();
$rtf->Output();
?>

or this

<?php
require('frtf.php');

$rtf=new FRTF();
$rtf->Open();
$rtf->SetPaperSize('A4');
$rtf->SetPageOrientation('L');
$rtf->SetViewKind('Page');
$rtf->SetViewScale(100);
$rtf->SetViewZk('None');
$rtf->Write("The
          first text to be diplayed");
$rtf->Write("This
          string will be displayed continously",'no');
$rtf->Write('Another
          string in a new paragraph');
$rtf->Close();
$rtf->Output();
?>

and you'll obtain this:


Sample 3

If you want to create your RTF document locally, into a file named 'loco.rtf' please write the following lines in your PHP file:

<?php
require('frtf.php');

$rtf=new FRTF();
$rtf->Open();
$rtf->SetPaperSize('A4');
$rtf->SetPageOrientation('L');
$rtf->SetViewKind('Page');
$rtf->SetViewScale(100);
$rtf->SetViewZk('None');
$rtf->Write("The
          first text to be diplayed");
$rtf->Write("This
          string will be displayed continously",'no');
$rtf->Write('Another
          string in a new paragraph');
$rtf->Close();
$rtf->Output('loco.rtf');
?>

You'll find the result of the script locally, into the file '../loco.rtf'.


License

License agreement for RTFGen V 1.0 - Basic Edition

Copyright © 2004-2005. Cristian Muraru. All Rights Reserved.

The 'Software' bellow refers strictly to RTFGen V 1.0 - Basic Edition; and a 'work based on the Software' means either the Software or any derivative work under copyright law: that is to say, a work containing the Software or a portion of it, either verbatim or with modifications and/or translated into another language.

This license agreement is a legal agreement between you (either an individual or a single entity) and the author of this Software package.
By installing or otherwise using this Software you agree to be bound by this agreement.

If you do not agree to the terms of this Agreement, you may not install or use this Software.

This Agreement will immediately and automatically terminate without notice if you fail to comply with any term or condition of this Agreement. You agree upon termination to promptly destroy the Software product together with all of its component parts, prior and replacement versions, and all copies and modifications thereof in any form.

The Software is copyrighted freeware. The Software can be used without charge but the author retains full rights to the program. All rights reserved.

You are hereby licensed to make as many copies of this Software and documentation as you wish; give exact copies of the original Software to anyone; and distribute the Software and documentation in its unmodified form via electronic means. There is no charge for any of the above.

You are specifically prohibited from charging, or requesting donations, for any such copies, however made; and from distributing the Software and/or documentation with other products (commercial or otherwise) without prior written permission.

If the Software is distributed within mass media publication (CD-ROM, diskettes, ZIP drives, streamer or similar) we would like to receive free copy of that publication. If it is distributed electronically by systems with paid access we would like annual free subscription.

Publishers and distributors of freeware & shareware software who wants to publish this program along with others are asked to send us a copy of each publication containing our product.

You may not rent or lease the Software.

The author of this software does not guarantee that this software is free from bugs or free from viruses.

The author may, from time to time, revise or update the Software. In so doing, the author incurs no obligation to furnish such revision or updates to you.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL OTHER WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, CONFORMANCE WITH DESCRIPTION, TITLE AND NON-INFRINGEMENT OF THIRD PARTY RIGHTS.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR EXEMPLARY DAMAGES OR LOST PROFITS WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE PRODUCT, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY CASE, THE AUTHOR'S CUMULATIVE AND ENTIRE LIABILITY TO YOU OR ANY OTHER PARTY FOR ANY LOSS OR DAMAGES RESULTING FROM ANY CLAIMS, DEMANDS OR ACTIONS ARISING OUT OF OR RELATING TO THIS AGREEMENT SHALL NOT EXCEED THE PURCHASE PRICE PAID FOR THIS LICENSE.

Should any term of these terms and conditions be declared void or unenforceable by any court of competent jurisdiction, such declaration shall have no effect on the remaining terms hereof.