Class: JekyllPandocMultipleFormats::Printer
- Inherits:
-
Object
- Object
- JekyllPandocMultipleFormats::Printer
- Defined in:
- lib/jekyll-pandoc-multiple-formats/printer.rb
Direct Known Subclasses
Constant Summary collapse
- TEMPLATE =
<<-EOT.gsub(/^\s+/, '') \\documentclass[@@sheetsize@@,10pt]{article} \\usepackage{pgfpages} \\usepackage{pdfpages} \\pgfpagesuselayout{@@nup@@ on 1}[@@sheetsize@@,@@extra_options@@] \\begin{document} \\includepdf[pages={@@pages@@}]{@@document@@} \\end{document} EOT
- SHEET_SIZES =
TODO allow custom sheet sizes
{ a7paper: 2, a6paper: 4, a5paper: 8, a4paper: 16, a3paper: 32, a2paper: 64, a1paper: 128, a0paper: 256 }
Instance Attribute Summary collapse
-
#extra_options ⇒ Object
Returns the value of attribute extra_options.
-
#nup ⇒ Object
Returns the value of attribute nup.
-
#original_file ⇒ Object
Returns the value of attribute original_file.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#papersize ⇒ Object
Returns the value of attribute papersize.
-
#relative_path(from) ⇒ Object
Returns the value of attribute relative_path.
-
#sheetsize ⇒ Object
Returns the value of attribute sheetsize.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(file, papersize = nil, sheetsize = nil, extra_options = nil) ⇒ Printer
constructor
A new instance of Printer.
- #is_landscape? ⇒ Boolean
- #render_template ⇒ Object
- #round_to_nearest(int, near) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(file, papersize = nil, sheetsize = nil, extra_options = nil) ⇒ Printer
Returns a new instance of Printer.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 57 def initialize(file, papersize = nil, sheetsize = nil, = nil) return unless /\.pdf\Z/ =~ file return unless pdf = PDF::Info.new(file) @original_file = File.realpath(file) @papersize = papersize || 'a5paper' @sheetsize = sheetsize || 'a4paper' @pages = pdf.[:page_count] @nup = SHEET_SIZES[@sheetsize.to_sym] / SHEET_SIZES[@papersize.to_sym] @extra_options = || '' # These layouts require a landscape page @extra_options << 'landscape' if is_landscape? self end |
Instance Attribute Details
#extra_options ⇒ Object
Returns the value of attribute extra_options.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def @extra_options end |
#nup ⇒ Object
Returns the value of attribute nup.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def nup @nup end |
#original_file ⇒ Object
Returns the value of attribute original_file.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def original_file @original_file end |
#output_file ⇒ Object
Returns the value of attribute output_file.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def output_file @output_file end |
#pages ⇒ Object
Returns the value of attribute pages.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def pages @pages end |
#papersize ⇒ Object
Returns the value of attribute papersize.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def papersize @papersize end |
#relative_path(from) ⇒ Object
Returns the value of attribute relative_path.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def relative_path @relative_path end |
#sheetsize ⇒ Object
Returns the value of attribute sheetsize.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def sheetsize @sheetsize end |
#template ⇒ Object
Returns the value of attribute template.
54 55 56 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 54 def template @template end |
Instance Method Details
#is_landscape? ⇒ Boolean
88 89 90 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 88 def is_landscape? [2,8,32,128].include? @nup end |
#render_template ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 96 def render_template @template = TEMPLATE .gsub('@@nup@@', @nup.to_s) .gsub('@@sheetsize@@', @sheetsize) .gsub('@@extra_options@@', @extra_options) .gsub('@@document@@', @original_file) .gsub('@@pages@@', to_nup * ',') end |
#round_to_nearest(int, near) ⇒ Object
92 93 94 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 92 def round_to_nearest(int, near) (int + (near - 1)) / near * near end |
#write ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/jekyll-pandoc-multiple-formats/printer.rb', line 78 def write # Create the imposed file pdflatex = RTeX::Document.new(template) pdflatex.to_pdf do |pdf_file| FileUtils.cp pdf_file, @output_file end File.exists? @output_file end |