Class: HexaPDF::Document
- Inherits:
-
Object
- Object
- HexaPDF::Document
- Defined in:
- lib/pdf_paradise/hexapdf/hexapdf.rb
Instance Method Summary collapse
-
#add_this_font(font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf') ⇒ Object
(also: #add_font)
# === add_this_font.
-
#create_pie_chart(use_this_stroke_colour = :default, use_this_fill_colour = 'ddddff', radius = 75, store_into_this_pdf_file = 'arcs.pdf') ⇒ Object
(also: #pie_chart)
# === create_pie_chart ========================================================================= #.
-
#optimize_this_pdf_file(this_pdf_file = '/Depot/j/foobar.pdf', store_into_this_pdf_file = 'optimized_pdf_file.pdf') ⇒ Object
(also: #optimise_this_pdf_file)
# === optimize_this_pdf_file.
Instance Method Details
#add_this_font(font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf') ⇒ Object Also known as: add_font
#
add_this_font
This method can be used to add a specific font.
#
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pdf_paradise/hexapdf/hexapdf.rb', line 39 def add_this_font( font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf' ) case font_path # ======================================================================= # # === :hack # ======================================================================= # when :hack, :default font_path = '/usr/share/fonts/truetype/hack/Hack-Regular.ttf' end puts "Adding the font from: #{font_path}" return self.fonts.add(font_path) end |
#create_pie_chart(use_this_stroke_colour = :default, use_this_fill_colour = 'ddddff', radius = 75, store_into_this_pdf_file = 'arcs.pdf') ⇒ Object Also known as: pie_chart
#
create_pie_chart
#
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pdf_paradise/hexapdf/hexapdf.rb', line 57 def create_pie_chart( # doc = HexaPDF::Document.new, use_this_stroke_colour = :default, use_this_fill_colour = 'ddddff', radius = 75, store_into_this_pdf_file = 'arcs.pdf' ) doc = self if use_this_stroke_colour.is_a? Hash # ===================================================================== # # === :store_into # # Usage example: # # create_pie_chart(doc, store_into: 'bla.pdf') # # ===================================================================== # if use_this_stroke_colour.has_key? :store_into store_into_this_pdf_file = use_this_stroke_colour.delete(:store_into) use_this_stroke_colour = :default end end case use_this_stroke_colour when :default use_this_stroke_colour = '777777' end page = doc.pages.add # Add a new page. canvas = page.canvas # ======================================================================= # # A centered pie chart: # ======================================================================= # center = [page.box.width * 0.75, page.box.height * 0.85] canvas.stroke_color(use_this_stroke_colour) pie = canvas.graphic_object(:solid_arc, cx: center[0], cy: center[1], outer_a: radius, outer_b: radius) canvas.fill_color(use_this_fill_colour) canvas.draw(pie, start_angle: 30, end_angle: 110).fill_stroke canvas.fill_color('ffdddd') canvas.draw(pie, start_angle: 110, end_angle: 130).fill_stroke canvas.fill_color('ddffdd') canvas.draw(pie, start_angle: 130, end_angle: 30).fill_stroke doc.write(store_into_this_pdf_file, optimize: true) return canvas end |
#optimize_this_pdf_file(this_pdf_file = '/Depot/j/foobar.pdf', store_into_this_pdf_file = 'optimized_pdf_file.pdf') ⇒ Object Also known as: optimise_this_pdf_file
#
optimize_this_pdf_file
This method can be used to optimise a given .pdf file.
#
24 25 26 27 28 29 30 31 32 |
# File 'lib/pdf_paradise/hexapdf/hexapdf.rb', line 24 def optimize_this_pdf_file( this_pdf_file = '/Depot/j/foobar.pdf', store_into_this_pdf_file = 'optimized_pdf_file.pdf' ) HexaPDF.optimize_this_pdf_file( this_pdf_file, store_into_this_pdf_file ) end |