Method: CombinePDF.create_table
- Defined in:
- lib/combine_pdf/api.rb
.create_table(options = {}) ⇒ Object
makes a PDF object containing a table
all the pages in this PDF object are PDFWriter objects and are writable using the texbox function (should you wish to add a title, or more info)
the main intended use of this method is to create indexes (a table of contents) for merged data.
example:
pdf = CombinePDF.create_table headers: ["header 1", "another header"], table_data: [ ["this is one row", "with two columns"] , ["this is another row", "also two columns", "the third will be ignored"] ]
pdf.save "table_file.pdf"
accepts a Hash with any of the following keys as well as any of the Page_Methods#textbox options:
- headers
-
an Array of strings with the headers (will be repeated every page).
- table_data
-
as Array of Arrays, each containing a string for each column. the first row sets the number of columns. extra columns will be ignored.
- font
-
a registered or standard font name (see Page_Methods). defaults to nil (:Helvetica).
- header_font
-
a registered or standard font name for the headers (see Page_Methods). defaults to nil (the font for all the table rows).
- max_font_size
-
the maximum font size. if the string doesn’t fit, it will be resized. defaults to 14.
- column_widths
-
an array of relative column widths ([1,2] will display only the first two columns, the second twice as big as the first). defaults to nil (even widths).
- header_color
-
the header color. defaults to [0.8, 0.8, 0.8] (light gray).
- main_color
-
main row color. defaults to nil (transparent / white).
- alternate_color
-
alternate row color. defaults to [0.95, 0.95, 0.95] (very light gray).
- font_color
-
font color. defaults to [0,0,0] (black).
- border_color
-
border color. defaults to [0,0,0] (black).
- border_width
-
border width in PDF units. defaults to 1.
- header_align
-
the header text alignment within each column (:right, :left, :center). defaults to :center.
- row_align
-
the row text alignment within each column. defaults to :left (:right for RTL table).
- direction
-
the table’s writing direction (:ltr or :rtl). this reffers to the direction of the columns and doesn’t effect text (rtl text is automatically recognized). defaults to :ltr.
- max_rows
-
the number of rows per page, INCLUDING the header row. deafults to 25.
- page_size
-
the size of the page in PDF points. defaults to [0, 0, 595.3, 841.9] (A4).
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/combine_pdf/api.rb', line 86 def create_table( = {}) [:max_rows] = [:rows_per_page] if [:rows_per_page] page_size = [:page_size] || [0, 0, 595.3, 841.9] table = PDF.new() page = nil until [:table_data].empty? page = create_page page_size page.write_table table << page end table end |