class Workspace::File::PdfPage

Attributes

page[R]
pdf[R]

Public Class Methods

new(pdf, page) click to toggle source
# File workspace-pdf.rb, line 36
def initialize(pdf, page)
  @pdf = pdf
  @page = page
end

Public Instance Methods

export(output_file, width: nil) { |context| ... } click to toggle source
# File workspace-pdf.rb, line 65
def export(output_file, width: nil, &block)
  output_width = @page.size[0]
  output_height = @page.size[1]
  output_scale = 1.0
  unless width.nil?
    output_scale = width / output_width
    output_width *= output_scale
    output_height *= output_scale
  end
  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, output_width, output_height)
  context = Cairo::Context.new(surface)
  context.set_source_rgb(1, 1, 1)
  context.paint
  context.scale(output_scale, output_scale)
  context.render_poppler_page(@page)
  yield(context) if block_given?
  output_file.dir.create unless output_file.dir.exists?
  surface.write_to_png(output_file.to_s)
  context.target.finish
end
height() click to toggle source
# File workspace-pdf.rb, line 57
def height
  page.size[1]
end
index() click to toggle source
# File workspace-pdf.rb, line 41
def index
  page.index
end
number() click to toggle source
# File workspace-pdf.rb, line 45
def number
  page.index + 1
end
ratio() click to toggle source
# File workspace-pdf.rb, line 61
def ratio
  width / height
end
title() click to toggle source
# File workspace-pdf.rb, line 49
def title
  "Page #{number}"
end
width() click to toggle source
# File workspace-pdf.rb, line 53
def width
  page.size[0]
end