{"id":13858828,"url":"https://github.com/clbustos/rtf","last_synced_at":"2025-07-14T01:31:51.065Z","repository":{"id":46192843,"uuid":"576268","full_name":"clbustos/rtf","owner":"clbustos","description":"Bug fix fork of gitified copy of the ruby-rtf gem by thechrisoshow/rtf","archived":false,"fork":true,"pushed_at":"2021-11-08T12:53:01.000Z","size":248,"stargazers_count":28,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-05T07:04:37.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://rubyforge.org/projects/ruby-rtf/","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"thechrisoshow/rtf","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clbustos.png","metadata":{"files":{"readme":"README.rdoc","changelog":"History.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-03-23T19:41:27.000Z","updated_at":"2024-08-06T17:24:21.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/clbustos/rtf","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/clbustos/rtf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clbustos%2Frtf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clbustos%2Frtf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clbustos%2Frtf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clbustos%2Frtf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clbustos","download_url":"https://codeload.github.com/clbustos/rtf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clbustos%2Frtf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265231067,"owners_count":23731514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T03:02:22.249Z","updated_at":"2025-07-14T01:31:50.734Z","avatar_url":"https://github.com/clbustos.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"== Ruby Rich Text Format (RTF) Library\nThe RTF library provides a pure Ruby set of functionality that can be used to\nprogrammatically create RTF documents. The main aim in developing this library\nis to ease the complexity involved in assembling RTF documents although some\nconsideration has also been given to generating documents that are easier to\nmanually interpret too.\n\nThis library does not include functionality for parsing RTF documents. Nor does\nthe library claim to provide extensive coverage of the RTF specification. The\nlibrary was developed mostly with reference to the RTF Pocket Guide by Sean M.\nBurke and some reference to the RTF specification itself. The introduction to\nthe RTF Pocket Guide states that the book covers version 1.7 of the RTF\nspecification so I guess, as this was the primary source, that this is the\nversion that the library covers too. Finally, no consideration was given to\nmaking the functionality within the library thread safe.\n\nIn creating this library I set out to make it reasonably easy to create RTF\ndocuments in code. Having said that I'm certain that it is possible to generate\ninvalid RTF documents with this library.\n\n=== Known Issues\nI've tried to assemble a reasonably extensive (although I won't claim\nexhaustive) unit test for the library. Despite that, this is an early release of\nthe code and I'm sure there will be issues with it given the complexity inherent\nin RTF. The following are issues that I'm already aware of with the library...\n\n* The implementation of headers and footers is incomplete. Stick to using\n  universal headers and footers for the time being.\n\n* The library makes no attempt to split large chunks of text into separate\n  lines. This can make editing the resulting document in a text editor a little\n  awkward.\n\n* RTF is, when it comes down to it, a Microsoft standard. As a result I have\n  taken Word and Wordpad to be definitive when it comes to displaying the RTF\n  documents generated by the library. I have tried things like Abiword and\n  Open Office with varying degrees of success. I'm certainly not saying that\n  this is due to deficencies in these particular applications as it could\n  equally be a lack of my understanding of the RTF standard or problems with my\n  implementation. Still, I think I should mention the point that I don't get\n  consistent appearance across all of the RTF viewers I've tried.\n\n=== To Do\nThis section details that areas where I feel the library is currently lacking\nor incomplete. I hope to address the things detailed here in later releases of\nthe code.\n\n* Check into RTF image handling with a view to adding support for the insertion\n  of images into a Document.\n* Provide a complete implementation for the headers and footers.\n\n=== Some Examples\nOkay, so how is the library used. Well lets look at some examples to see if we\ncan cast a little light on the matter. The examples provided here assume that\nyou are already familiar with the Ruby language. So, for a start, consider...\n\n   require 'rubygems'\n   require 'rtf'\n\nThe first thing to look at here at the are the first two lines. The RTF library\nis provided as a Ruby gem and these two lines load the libraries functionality\ninto the script. The third line of code includes the RTF module into the current\nname space. This is a convenience mechanism that saves on specifically having\nto refer to the module when accessing the RTF library. Next we want to create\nan RTF document and that is done like this...\n\n   document = RTF::Document.new(RTF::Font.new(RTF::Font::ROMAN, 'Times New Roman'))\n\nThis line of code creates a new Document object, specifying that the default\nfont for the document will the the Times New Roman font. So we have a document,\nwhat can we do with it. Well, lets add a short paragraph of text...\n\n   document.paragraph \u003c\u003c \"This is a short paragraph of text.\"\n\nThat's fine, but what if we wanted to extend that paragraph or we simply wanted\nto add more text than we've added here? Well, the paragraph method accepts a\nblock to which it passes the actual paragraph object, so we could do something\nlike the following...\n\n   document.paragraph do |p|\n      p \u003c\u003c \"This is the first sentence in the paragraph. \"\n      p \u003c\u003c \"This is the second sentence in the paragraph. \"\n      p \u003c\u003c \"And this is the third sentence in the paragraph.\"\n   end\n\nThis is a common approach used by the RTF library, allowing a block to define\nthe scope of a document element. Lets see a more complicated example of this\nin which we apply a number of document effects. Lets say that we want to insert\nsome code into the document. We want the code to appear in the document slightly\nindented on the left hand side, in a non-proportionately space font and we want\nit in bold text. Heres the code that shows how to do that...\n\n   01 styles = {}\n   02 styles['PS_CODE'] = ParagraphStyle.new\n   03 styles['CS_CODE'] = CharacterStyle.new\n   04\n   05 styles['PS_CODE'].left_indent = 200\n   06 styles['CS_CODE'].font        = Font.new(Font::MODERN, 'Courier')\n   07 styles['CS_CODE'].bold        = true\n   08\n   09 document.paragraph(styles['PS_CODE']) do |n1|\n   10    n1.apply(styles['CS_CODE']) do |n2|\n   11       n2 \u003c\u003c \"count = 0\"\n   12       n2.line_break\n   13       n2 \u003c\u003c \"File.open('file.txt', 'r') do |file|\"\n   14       n2.line_break\n   15       n2 \u003c\u003c \"   file.each_line {|line| count += 1}\"\n   16       n2.line_break\n   17       n2 \u003c\u003c \"end\"\n   18       n2.line_break\n   19       n2 \u003c\u003c \"puts \\\"File contains \\#{count} lines.\\\"\"\n   20    end\n   21 end\n\nThis is a much larger piece of code and covers a number of topics that need to\nbe addressed. I have included line numbers with code so that individual elements\ncan be referenced. Lines 1 to 3 are the first new elements. Here we create a\nHash and assign it to a variable called styles. On the next two lines we create\ntwo style objects, one that can be applied to paragraphs and one that applies\nto characters.\n\nOn lines 5 to 7 we update settings on the style objects we've created. We set\nthe left indentation value of the paragraph style to 200. The 200 in this case\nrefers to a measurement of twips. A twip is a type setting measurement that\nequates to one twentieth of a point (about a fifty seventh of a millimetre or\none seventy second of an inch). This is the measurement scale used by RTF\ndocuments so it is also employed in the library.\n\nOn lines 6 and 7 we update the character style to use a courier font and to\napply bold styling to the text. On line 9 we start a new paragraph in our\ndocument. This differs from our previous use of this method in that we specify\na style that will be applied to the paragraph created, the paragraph style we\nhad prepared earlier.\n\nThe block accompanying the paragraph method takes the single parameter that we\nhave seen previously. At this point its probably a good idea to point out that\nthe elements that make up an RTF document created with the library are all\nstored as nodes in a tree. We've named the one passed to the paragraph method as\nn1 to reflect this.\n\nWithin the block we've called a method on the paragraph node called apply. This\nmethod applies a character style and we're using the one we prepared earlier.\nLike the call to the paragraph method, the apply method is passed a block. All\ntext added to the blocks node (n2 in this case) will have the styling we've\ndefined (bold courier font) applied to it.\n\nNote, that within the apply block we could still use the n1 node. Any text we\nadded to this would appear in the paragraph but wouldn't be styled and, it\nshould be noted, will appear before any text added to n2 (as the n2 node only\nbecomes part of the document when the apply block completes).\n\nWithin the apply method block we add some lines of text to the n2 node. Note\nthat, as this is all encompassed within the parapgraph block, all the text is\npart of a single paragraph. To get each of the lines of code to appear on a\nline of their own we have used the line_break method which inserts a carriage\nreturn into the document. Note you should use this method to insert line breaks\nrather than trying to add a string containing \"\\n\". RTF is a text based standard\nand won't treat \"\\n\" as you're expecting. You should note also that we've had to\nescape the '#' in one of the code lines to stop Ruby considering it as an\ninterpolated value.\n\nOkay, so we've seen have the basics of creating a document and adding elements\nto that document. How do we get what we've created to a file. Well thats\nactually quite straight forward. As was mentioned previously, RTF is a text\nbased standard so you simply generate the RTF and write it to a file. Heres an\nexample...\n\n   File.open('my_document.rtf', 'w') {|file| file.write(document.to_rtf)} # existing file by this name will be overwritten\n\nThere you have it. You've been given a quick overview of the basics of using\nthe library. For more information consult the HTML based API documentation that\nis installed with the library gem (if you're reading this you may already be\nlooking at this documentation). Another source of information is the examples\ndirectory, so check that out too.\n\n== CONTRIBUTORS\n\n=== Individuals\n* Marcello Barnaba\n* Claudio Bustos\n* Sam Mullen\n* Chris O'Sullivan\n\n===Organizations\n* IFAD\n\nCOPYRIGHT\nCopyright (c) 2009-2012 Peter Wood. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclbustos%2Frtf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclbustos%2Frtf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclbustos%2Frtf/lists"}