PHP Classes

PHP RTF Tools: Parse and generate RTF documents using templates

Recommend this page to a friend!
  Info   View files Example   View files View files (44)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog (1)    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 73%Total: 707 All time: 4,642 This week: 103Up
Version License PHP version Categories
rtftools 1.0.4GNU General Publi...5.6PHP 5, Files and Folders, Text proces..., P...
Description 

Author

This package can parse and generate RTF documents using templates.

Currently it provides different classes that can:

- Process RTF documents from files or strings (RtfDocument class)
- Rewrite RTF documents splitting their tags into multiple lines so it can be easy to compare and find differences between two files using diff like utilities (RtfBeautifier)
- Extract raw text from RTF documents with some basic formatting capabilities (RtfBeautifier)
- Process RTF document templates with a macro language that suppports:

* Inline variables expansion within the document (variables are supplied by the caller)
* Expressions evaluation and replacement using PHP syntax (for example : date ( 'Y-m-d H:i:s' ))
* IF/ELSEIF/ELSE/ENDIF constructs, to conditionally include text in the output document
* REPEAT/FOR loops that can repeat blocks of text
* FOREACH loops that operate on array values supplied by the caller
(RtfTemplater class)

- Merge several RTF documents together including using the template processing objects, external files or strings, preserving details like fonts, colors, styles and avoiding page number repetition (RtfMerger class)
- A generic Rtf parser class is also provided, that can be used if you need more advanced capabilities when interpreting Rtf document contents (RtfParser class).

All the classes in this package have been designed to be able to process Rtf documents that may be larger than the available memory. This is useful when you need to handle at once several Rtf documents whose total size may exceed your current PHP memory limit.

Innovation Award
PHP Programming Innovation award nominee
September 2016
Number 3


Prize: PHP Tools for Visual Studio Personal license
Comparing word processing documents programmatically to see what was changed is a hard problem because you need to parse the documents and determine how to compare them.

This package provides an alternative solution to simplify this task.

Many Word processing documents can export documents in RTF (Rich Text Format). This is a text based format based on marks that identify different values in the documents like fonts, text formatting attributes, colors, etc..

If you save your Word processor documents in the RTF format, this package can easily render the document data in a beautified way that make it easier to compare document using a diff-like text comparison program.

Manuel Lemos
Picture of Christian Vigh
  Performance   Level  
Name: Christian Vigh <contact>
Classes: 32 packages by
Country: France France
Age: 57
All time rank: 13810 in France France
Week rank: 10 Up1 in France France Up
Innovation award
Innovation award
Nominee: 20x

Winner: 3x

Example

<?php
   
/****************************************************************************************************
     *
     * This script demonstrates the Rtf text templating capabilities of the RtfTemplater classes
     * (RtfStringTemplater or RtfFileTemplater).
     *
     * It extract text contents from file "template.rtf", which contains a whole set of templating
     * instructions.
     *
     ****************************************************************************************************/

   
include ( '../../sources/RtfTemplater.phpclass' ) ;

   
$variables =
       [
       
'VNAME1' => 'the value of vname1',
       
'VNAME2' => 'the value of vname2',
       
'INDEX' => 17,
       
'ARRAY' => [ 'string a', 'string b', 'string c' ]
        ] ;

    
$templater = new RtfStringTemplater ( file_get_contents ( 'template.rtf' ), $variables ) ;
    
$templater -> SaveTo ( 'sample.rtf' ) ;


  Files folder image Files  
File Role Description
Files folder imageexamples (1 file, 4 directories)
Files folder imagehelp (7 files, 1 directory)
Files folder imagesources (8 files, 1 directory)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file NOTICE Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
Files folder imagebeautifier (4 files)
Files folder imagemerger (5 files)
Files folder imagetemplater (3 files)
Files folder imagetexter (2 files)
  Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  /  beautifier  
File Role Description
  Accessible without login Plain text file beautifier.php Example Example script
  Accessible without login Plain text file beautifier_perf.php Example Example script
  Accessible without login Plain text file create_samples.php Aux. Auxiliary script
  Accessible without login Plain text file sample.rtf Data Auxiliary data

  Files folder image Files  /  examples  /  merger  
File Role Description
  Accessible without login Plain text file merger.php Example Example script
  Accessible without login Plain text file sample1.rtf Data Auxiliary data
  Accessible without login Plain text file sample2.rtf Data Auxiliary data
  Accessible without login Plain text file sample3.rtf Data Auxiliary data
  Accessible without login Plain text file sample4.rtf Data Auxiliary data

  Files folder image Files  /  examples  /  templater  
File Role Description
  Accessible without login Plain text file sample.rtf Data Auxiliary data
  Accessible without login Plain text file template.rtf Data Auxiliary data
  Accessible without login Plain text file templater.php Example Example script

  Files folder image Files  /  examples  /  texter  
File Role Description
  Accessible without login Plain text file sample.rtf Data Auxiliary data
  Accessible without login Plain text file texter.php Example Example script

  Files folder image Files  /  help  
File Role Description
Files folder imageimages (9 files)
  Accessible without login Plain text file help.css Data Auxiliary data
  Accessible without login HTML file help.html Doc. Documentation
  Accessible without login Plain text file README.beautifier.md Doc. Documentation
  Accessible without login Plain text file README.merger.md Doc. Documentation
  Accessible without login Plain text file README.parser.md Doc. Documentation
  Accessible without login Plain text file README.templater.md Doc. Documentation
  Accessible without login Plain text file README.texter.md Doc. Documentation

  Files folder image Files  /  help  /  images  
File Role Description
  Accessible without login Image file Modeling-RtfBeautifier.png Data Auxiliary data
  Accessible without login Image file Modeling-RtfDocument.png Data Auxiliary data
  Accessible without login Image file Modeling-RtfMerger.png Icon Icon image
  Accessible without login Image file Modeling-RtfParser.png Data Auxiliary data
  Accessible without login Image file Modeling-RtfTemplater.png Data Auxiliary data
  Accessible without login Image file Modeling-RtfTexter.png Data Auxiliary data
  Accessible without login Image file Modeling-RtfToken.png Data Auxiliary data
  Accessible without login Image file tree-collapse.png Icon Icon image
  Accessible without login Image file tree-expand.png Icon Icon image

  Files folder image Files  /  sources  
File Role Description
Files folder imageMerger (2 files)
  Plain text file RtfBeautifier.phpclass Class Class source
  Plain text file RtfDocument.phpclass Class Class source
  Plain text file RtfMerger.phpclass Class Class source
  Plain text file RtfParser.phpclass Class Class source
  Plain text file RtfTemplater.phpclass Class Class source
  Plain text file RtfTexter.phpclass Class Class source
  Plain text file RtfToken.phpclass Class Class source
  Plain text file SearchableFile.phpclass Class Class source

  Files folder image Files  /  sources  /  Merger  
File Role Description
  Plain text file RtfMergerDocument.phpclass Class Class source
  Plain text file RtfMergerHeader.phpclass Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:707
This week:0
All time:4,642
This week:103Up
User Ratings User Comments (1)
 All time
Utility:91%StarStarStarStarStar
Consistency:95%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:73%StarStarStarStar
Rank:212