{"id":21597266,"url":"https://github.com/spheresoftware/pdf_gen","last_synced_at":"2025-03-18T11:22:08.358Z","repository":{"id":1093384,"uuid":"948807","full_name":"SphereSoftware/pdf_gen","owner":"SphereSoftware","description":"High level wrapper around PDF::Writer","archived":false,"fork":false,"pushed_at":"2011-02-11T08:53:49.000Z","size":1844,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-19T05:39:00.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://sphereconsultinginc.github.com/pdf_gen/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SphereSoftware.png","metadata":{"files":{"readme":"README.rdoc","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-09-29T16:23:43.000Z","updated_at":"2014-11-21T07:21:05.000Z","dependencies_parsed_at":"2022-08-16T12:00:37.987Z","dependency_job_id":null,"html_url":"https://github.com/SphereSoftware/pdf_gen","commit_stats":null,"previous_names":["sphereconsultinginc/pdf_gen"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SphereSoftware%2Fpdf_gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SphereSoftware%2Fpdf_gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SphereSoftware%2Fpdf_gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SphereSoftware%2Fpdf_gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SphereSoftware","download_url":"https://codeload.github.com/SphereSoftware/pdf_gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244208607,"owners_count":20416110,"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-11-24T18:08:35.352Z","updated_at":"2025-03-18T11:22:08.332Z","avatar_url":"https://github.com/SphereSoftware.png","language":"Ruby","readme":"== Pdf_gen\npdf_gen is a high-level wrapper around {PDF::Writer}[https://github.com/sandal/pdf-writer] library which allows to create PDF documents in an easy way with a layout similar to HTML.\n\n== Install\n  gem install pdf_gen\n\n== Usage\nAll package entities are located within the PDFGen module.\nPDF file generation can be made in the following way:\n\n  require \"pdf_gen\"\n\n  PDFGen::document PDF::Writer.new, 0.cm do\n    # pdf generation code here\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n\n== Construction Elements\n\n=== Caption\nAn object which allows to represent some parts of the text in PDF file. \nThis object has such properties as width, justification, pad_top (indent from the left side of the page), pad_bottom, pad_left, pad_right, text_color, font_size and border.\nThe Border, in its turn, can be characterized by border_color, border_style (solid or dotted) and border_width (in cm or pixels).\nSupport Properties:\n  pad_top - integer\n  pad_bottom - integer\n  pad_left - integer\n  pad_right - integer\n  paddings - integer\n  border - true|false\n  border_top - true|false\n  border_bottom - true|false\n  border_left - true|false\n  border_right - true|false\n  border_style - :solid | :dotted\n  border_widht - integer\n  border_color - object of color-tools*. Color::RGB::Red|Color::RGB.from_html(\"#ccc\")| other\n  background_color - object of color-tools*. Color::RGB::Red|Color::RGB.from_html(\"#ccc\")| other\n  width - integer\n  height - integer\n  \n  *color-tools http://ruby-pdf.rubyforge.org/color-tools/\n\n=== Image\nAn object which allows to add images with filename extensions *.jpg and *.png in PDF file. \nThis object has such properties as width, pad_top, pad_bottom, pad_left, pad_right and border.\n\n  require \"pdf_gen\"\n\n  PDFGen::document PDF::Writer.new, 2.cm do\n    image_data = open(File.expand_path('ruby_logo.jpg'), \"rb\") { |file| file.read }\n    image image_data, :width =\u003e 250\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n  \nSupport Properties:\n  *the same as caption`s properties\n  \n=== Span\nAn object which allows setting several objects across the page. \nThis object has such properties as width, pad_top, pad_bottom, pad_left, pad_right, border and background_color.\n\n  PDFGen::document PDF::Writer.new, 2.cm do\n    span :width =\u003e 10.cm, :pad_left =\u003e 2.cm do\n      caption ' first '*50, :width =\u003e 4.cm\n      caption ' second '*50, :width =\u003e 4.cm\n      elements :border =\u003e true    #group set params\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n  \nSupport Properties:\n  *the same as caption`s properties\n  vertical_interval - integer\n  vartical_align - true | false\n  \n=== Div\nAn object which allows setting several elements in the vertical format. \nThis object has such properties as width, horizontal_interval, pad_top, pad_bottom, pad_left, pad_right, border and background_color. \nDiv element can be divided across pages automatically.\n\n  PDFGen::document PDF::Writer.new, 2.cm do\n    div :width =\u003e 10.cm do\n      caption ' first '*50, :width =\u003e 4.cm\n      caption ' second '*50, :width =\u003e 4.cm\n      elements :border =\u003e true    #group set params\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n  \nSupport Properties:\n  *the same as caption`s properties\n  horizontal_interval - integer\n  horizontal_align - true | false\n\n=== Table\nAn object which allows creating tables in PDF file. This object has such elements as title, header, body and footer. \nThe columns can be made be adding “spans” inside the body of the table. \nThe table can have borders from specific sides, for example: “:border_right =\u003e true” or “:border_right =\u003e false”.\n\n  require \"pdf_gen\"\n\n  PDFGen::document PDF::Writer.new, 0.cm do\n    table do\n      title do\n         caption \"Transactions and Triggers\",\n       :text_color =\u003e Color::RGB::Red, :border =\u003e true, :justification =\u003e :center, :pad_bottom =\u003e 0.25.cm\n      end\n      header do\n        span do\n          caption \"Number\",\n                  :width =\u003e av_width / 2, :justification =\u003e :center, :border =\u003e true\n          caption \"Discription\",\n                  :width =\u003e av_width / 2, :justification =\u003e :center, :border =\u003e true\n        end\n      end\n      body do\n        span do\n          caption \"  Trigger \", :width =\u003e av_width / 2,\n                  :border_right =\u003e true, :border_left =\u003e true, :text_color =\u003e Color::RGB::Grey\n          caption \" - is a ... \", :width =\u003e av_width / 2,\n                  :border_right =\u003e true, :border_left =\u003e true, :text_color =\u003e Color::RGB::Grey\n        end\n      end\n      footer do\n        span do\n          caption \"1\", :width =\u003e av_width / 2, :justification =\u003e :center, :border =\u003e true\n          caption \"2\", :width =\u003e av_width / 2, :justification =\u003e :center, :border =\u003e true\n        end\n      end\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n\n=== Smart Table\nAn object which allows creating tables from Hash and ActiveRecord. If necessary, you can define the blocks of the title and footer independently.\nFor example:\n\n  table_data = {:columns =\u003e['id','name','email'],\n                :body =\u003e [[1,'Valeriy','valeriy@example.com'],\n                          [2,'Dmitriy','dmitriy@example.com']]}\n  PDFGen::document PDF::Writer.new, 0.cm do\n    div :paddings =\u003e 2 do\n      table :data_source =\u003e table_data\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n\nBuilding a table from ActiveRecord (ROR)\n\n  table_data = User.all\n  PDFGen::document PDF::Writer.new, 0.cm do\n    div :paddings =\u003e 2 do\n      table :data_source =\u003e table_data\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n\nCustom view\n\n  table_data = {:columns =\u003e['id','name','email'],\n                :body =\u003e [[1,'Valeriy','valeriy@example.com'],\n                          [2,'Dmitriy','dmitriy@example.com']]}\n  PDFGen::document PDF::Writer.new, 0.cm do\n    div :paddings =\u003e 2 do\n      table :data_source =\u003e table_data do\n         header do\n           row do\n             cell \"\u003cb\u003e#{ds.columns[0]}\u003c/b\u003e\", :justification =\u003e :center, :text_color =\u003e Color::RGB::Green\n             cell ds.columns[1], :justification =\u003e :center, :text_color =\u003e Color::RGB::Green\n             cell ds.columns[2], :justification =\u003e :center, :text_color =\u003e Color::RGB::Green           \n           end\n         end\n         body do\n           ds.each do |datarow|\n             row do\n               cell datarow[0]\n               cell \"\u003ci\u003e#{datarow[1]}\u003c/i\u003e\"\n               cell datarow[2]\n             end\n           end\n         end\n      end\n    end\n  end.save(\"#{File.basename(__FILE__, \".rb\")}.pdf\")\n\nWe can set the width of each column\n\n  row do\n    cell data[0], :width =\u003e av_width * 2/4\n    cell data[1], :width =\u003e av_width * 1/4\n    cell data[2], :width =\u003e av_width * 1/4\n  end\n\nMethod cell supports blocks, for example:\n\n  body do\n    ds.each do |datarow|\n      row do\n        cell datarow[1], :width =\u003e av_width / 2\n        cell datarow[2], :width =\u003e av_width / 4\n        cell :div, :width =\u003e av_width / 4, :paddings =\u003e 0.2.cm do\n              image(open(File.expand_path(\"example_image.png\"), \"rb\") { |file| file.read }, :width =\u003e av_width / 2)\n        end\n      end\n    end\n  end\n\nIn this case the first arguments can be \":div\", \":span\", \":table\" and others\n\n== Credits\n\n=== Team's line-up\n* Sphere Consulting Inc Development Team. \n\nCopyright (c) 2010 {Sphere Consulting Inc.}[http://www.sphereinc.com], released under the MIT license (see LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspheresoftware%2Fpdf_gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspheresoftware%2Fpdf_gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspheresoftware%2Fpdf_gen/lists"}