Sha256: 2799dff1032349373085d0e8dcfa56456872206646c93339e94e2a32af33cdaf

Contents?: true

Size: 1.18 KB

Versions: 24

Compression:

Stored size: 1.18 KB

Contents

module Softcover
  module Builders
    class Preview < Builder

      def build!
        # Recall that MOBI generation makes an EPUB as a side-effect.
        Softcover::Builders::Mobi.new.build!(preview: true)
        Softcover::Builders::Pdf.new.build!(preview: true)
        extract_pdf_pages
      end

      private

        # Extracts pages from the PDF using GhostScript.
        # The page range is set by the `pdf_preview_page_range` parameter
        # in book.yml so that authors can override the default range.
        def extract_pdf_pages
          input  = File.join('ebooks', manifest.filename + '.pdf')
          output = input.sub('.pdf', '-preview.pdf')
          range  = manifest.pdf_preview_page_range.split('..').map(&:to_i)
          cmd  = %(yes | #{ghostscript} -dBATCH -sOutputFile="#{output}")
          cmd += %( -dFirstPage=#{range.first} -dLastPage=#{range.last})
          cmd += %( -sDEVICE=pdfwrite "#{input}" >& /dev/null)
          execute cmd
        end

        def ghostscript
          filename = `which gs`.chomp
          message  = "Install GhostScript (should come with LaTeX)"
          @ghostscript ||= executable(filename, message)
        end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
softcover-0.8.0 lib/softcover/builders/preview.rb
softcover-0.7.11 lib/softcover/builders/preview.rb
softcover-0.7.10 lib/softcover/builders/preview.rb
softcover-0.7.9 lib/softcover/builders/preview.rb
softcover-0.7.8 lib/softcover/builders/preview.rb
softcover-0.7.7 lib/softcover/builders/preview.rb
softcover-0.7.6 lib/softcover/builders/preview.rb
softcover-0.7.5 lib/softcover/builders/preview.rb
softcover-0.7.4 lib/softcover/builders/preview.rb
softcover-0.7.3 lib/softcover/builders/preview.rb
softcover-0.7.2 lib/softcover/builders/preview.rb
softcover-0.7.1 lib/softcover/builders/preview.rb
softcover-0.7.0 lib/softcover/builders/preview.rb
softcover-0.6.10 lib/softcover/builders/preview.rb
softcover-0.6.9 lib/softcover/builders/preview.rb
softcover-0.6.7 lib/softcover/builders/preview.rb
softcover-0.6.6 lib/softcover/builders/preview.rb
softcover-0.6.5 lib/softcover/builders/preview.rb
softcover-0.6.4 lib/softcover/builders/preview.rb
softcover-0.6.3 lib/softcover/builders/preview.rb