Sha256: a0f67d1ea0578477326e4a08e03a3a06496f48093624dd6c083674869ce82595

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module Kitabu
  class Exporter
    class PDF < Base
      def export
        apply_footnotes!
        spawn_command ["prince", html_for_pdf.to_s, "-o", pdf_file.to_s]
        spawn_command ["prince", html_for_print.to_s, "-o", print_file.to_s]
      end

      def apply_footnotes!
        html = Footnotes::PDF.process(html_file.read).html
        create_html_file(html_for_print, html, 'print')
        create_html_file(html_for_pdf, html, 'pdf')
      end

      def create_html_file(target, html, class_name)
        html.css("html").first.set_attribute "class", class_name
        html.css("link[name=stylesheet]").first.set_attribute "href", "styles/#{class_name}.css"
        File.open(target, "w") {|f| f << html.to_html }
      end

      def html_for_pdf
        root_dir.join("output/#{name}.pdf.html")
      end

      def html_for_print
        root_dir.join("output/#{name}.print.html")
      end

      def html_file
        root_dir.join("output/#{name}.html")
      end

      def pdf_file
        root_dir.join("output/#{name}.pdf")
      end

      def print_file
        root_dir.join("output/#{name}.print.pdf")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kitabu-2.1.0 lib/kitabu/exporter/pdf.rb
kitabu-2.0.4 lib/kitabu/exporter/pdf.rb
kitabu-2.0.3 lib/kitabu/exporter/pdf.rb
kitabu-2.0.2 lib/kitabu/exporter/pdf.rb
kitabu-2.0.1 lib/kitabu/exporter/pdf.rb