Sha256: 0455c151dd0ce8ab09241073e0500b88ffabe73e84fe1dab0cb88ebfffc62722

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module BrDanfe
  class DanfeNfce
    PAGE_WIDTH = 8.cm
    PAGE_HEIGHT = 100.cm

    attr_reader :options

    def initialize(xml)
      @xml = BrDanfe::XML.new(xml)
      @pdf = DanfeNfceLib::Document.new(PAGE_WIDTH, PAGE_HEIGHT)
      @options = BrDanfe::Logo::Config.new
    end

    def save_pdf(filename)
      generate
      @pdf.render_file filename
    end

    def render_pdf
      generate
      @pdf.render
    end

    private

    def generate
      DanfeNfceLib::Header.new(@pdf, @xml, @options.logo, @options.logo_dimensions).render
      DanfeNfceLib::ProductList.new(@pdf, @xml).render
      DanfeNfceLib::TotalList.new(@pdf, @xml).render
      DanfeNfceLib::Key.new(@pdf, @xml).render
      DanfeNfceLib::Recipient.new(@pdf, @xml).render
      DanfeNfceLib::NfceIdentification.new(@pdf, @xml).render
      DanfeNfceLib::QrCode.new(@pdf, @xml).render
      DanfeNfceLib::Footer.new(@pdf, @xml).render

      resize_page_height
    end

    def resize_page_height
      @pdf.page.dictionary.data[:MediaBox] = [0, @pdf.y - 10, PAGE_WIDTH, PAGE_HEIGHT]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
br_danfe-0.12.0 lib/br_danfe/danfe_nfce.rb