Class: Arrolio::Renderer::Pdf
- Inherits:
-
Object
- Object
- Arrolio::Renderer::Pdf
- Includes:
- Assets, FontEmbedding, Metadata
- Defined in:
- lib/arrolio/renderer/pdf.rb,
lib/arrolio/renderer/pdf/assets.rb,
lib/arrolio/renderer/pdf/metadata.rb,
lib/arrolio/renderer/pdf/font_embedding.rb
Overview
Walks Output::Page and emits PDF bytes via Pdfrb. Supports
font embedding: pass font_paths: as a Hash mapping the
Style#font_name string to a TTF path, and the renderer will
subset + embed each font for the codepoints actually used
in the document.
Defined Under Namespace
Modules: Assets, FontEmbedding, Metadata
Constant Summary collapse
- MM_TO_PT =
2.83464567
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
Instance Method Summary collapse
- #header_footer_style ⇒ Object
-
#initialize ⇒ Pdf
constructor
A new instance of Pdf.
- #render(pages, io:, logo_path: nil, metadata: {}, font_paths: {}, context: nil, layout_spec: nil) ⇒ Object
Methods included from Metadata
#apply_metadata, #attach_xmp_metadata, #build_outline
Methods included from Assets
#cover_logo_style, #rasterize_svg, #register_image, #register_logo, #render_cover_logo, #resolve_image_for_pdfrb, #svg_to_png_cache_path
Methods included from FontEmbedding
#attach_to_resources, #collect_codepoints, #prepare_embedded_fonts
Constructor Details
#initialize ⇒ Pdf
Returns a new instance of Pdf.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/arrolio/renderer/pdf.rb', line 28 def initialize @document = Pdfrb::Document.new @fonts = FontRegistry.new(@document) @images = {} @font_paths = {} @font_embedders = {} @font_encoders = {} @font_refs = {} @link_annotator = LinkAnnotator.new(@document) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
26 27 28 |
# File 'lib/arrolio/renderer/pdf.rb', line 26 def document @document end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
26 27 28 |
# File 'lib/arrolio/renderer/pdf.rb', line 26 def fonts @fonts end |
Instance Method Details
#header_footer_style ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/arrolio/renderer/pdf.rb', line 53 def return @header_footer_style if @header_footer_style config = @layout_spec&. || {} @header_footer_style = { margin_top: (config['margin_top'] || 26.5) * MM_TO_PT, margin_bottom: (config['margin_bottom'] || 26.5) * MM_TO_PT, margin_lr: (config['margin_lr'] || 25.5) * MM_TO_PT, header_offset: (config['header_offset'] || 4) * MM_TO_PT, footer_offset: (config['footer_offset'] || 4) * MM_TO_PT, font_name: config['font_name'] || 'Helvetica', font_size: config['font_size'] || 9.0, rule_width: config['rule_width'] || 0.5 }.freeze end |
#render(pages, io:, logo_path: nil, metadata: {}, font_paths: {}, context: nil, layout_spec: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/arrolio/renderer/pdf.rb', line 39 def render(pages, io:, logo_path: nil, metadata: {}, font_paths: {}, context: nil, layout_spec: nil) @font_paths = font_paths.transform_keys(&:to_s) @layout_spec = layout_spec () () @logo_ref = register_logo(logo_path) (pages) pages.each { |page| render_page(page) } build_outline(context, pages) if context @document.write(io.is_a?(String) ? io : nil, io: io.is_a?(String) ? nil : io) end |