Link | encode_rtf |
Author | Johan Solve |
Category | String |
Version | 8.x |
License | Public Domain |
Posted | 30 Oct 2008 |
Updated | 30 Oct 2008 |
More by this author... |
When building RTF files by hand, the text content needs to be encoded properly according to RTF specifications. This tag encodes extended characters and linebreaks for use in RTF files, and converts the html tags <b>, <i> and <br> to the RTF correspondents.
This tag does NOT produce a complete RTF document, you need to take care of that yourself. It is only intended to help you encode the text properly.
Read more about the RTF format here:
http://en.wikipedia.org/wiki/Rich_Text_Format
http://search.cpan.org/~sburke/RTF-Writer-1.11/lib/RTF/Cookbook.pod
Keep in mind that Lasso can also create RTF files with the PDF tags using PDF_Doc(-format='rtf'), but this tag is useful if you need to hand craft RTF files according to a specific format instead of creating full RTF documents from scratch.
var('rtfdoc'=encode_rtf('This is a räksmörgås. Now we are done!'); // add RTF prolog and end of document $rtfdoc = '{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0 Times New Roman;}}' + $rtf_doc + '}'; // serve the file file_serve($rtfdoc, -file='myfile.rtf', -type='application/rtf');
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag('encode_rtf', -required='input'); local('output'=string(#input)); #output -> replace('\r\n', '\n') & replace('\r', '\n'); #output = encode_url(bytes(#output, 'windows-1252')); #output -> replace('%0a', '\n') & replace('%20', ' ') & replace('%3c', '<') & replace('%3e', '>'); #output -> replace(regexp(-find='
]*>', -replace='\n', -ignorecase)); #output -> replace('\n', '\\line '); #output -> replace(regexp(-find='%([0-9a-f]{2})', -replace='{\\\\\'\\1}', -ignorecase)); #output -> replace(regexp(-find=']*>(.*?)', -replace='{\\\\b \\1}', -ignorecase)); #output -> replace(regexp(-find=']*>(.*?)', -replace='{\\\\i \\1}', -ignorecase)); return(@#output); /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft