module Kramdown::Converter::Pdf::PrawnDocumentExtension

This module gets mixed into the Prawn::Document instance.

Attributes

converter[RW]

Access the converter instance from within Prawn

Public Instance Methods

embed_image(pdf_obj, info, options) click to toggle source

Override image embedding method for adding image positions to image_floats.

# File lib/kramdown/converter/pdf.rb, line 483
def embed_image(pdf_obj, info, options)
  # find where the image will be placed and how big it will be
  w,h = info.calc_image_dimensions(options)

  if options[:at]
    x,y = map_to_absolute(options[:at])
  else
    x,y = image_position(w,h,options)
    move_text_position h
  end

  #--> This part is new
  if options[:position] == :right
    image_floats << [page_number, x - 15, y, w + 15, h + 15]
  end

  # add a reference to the image object to the current page
  # resource list and give it a label
  label = "I#{next_image_id}"
  state.page.xobjects.merge!(label => pdf_obj)

  # add the image to the current page
  instruct = "\nq\n%.3f 0 0 %.3f %.3f %.3f cm\n/%s Do\nQ"
  add_content instruct % [ w, h, x, y - h, label ]
end
image_floats() click to toggle source
# File lib/kramdown/converter/pdf.rb, line 478
def image_floats
  @image_floats ||= []
end