Sha256: 1e32472b8534ddef7a7992f429519b957aab58338e8c9784264bb90d0e7bed85

Contents?: true

Size: 1.03 KB

Versions: 32

Compression:

Stored size: 1.03 KB

Contents

# # Images
#
# This example shows how to embed images into a PDF document, directly on a
# page's canvas and through the high-level [HexaPDF::Composer].
#
# Usage:
# : `ruby images.rb`
#

require 'hexapdf'

file = File.join(__dir__, 'machupicchu.jpg')

doc = HexaPDF::Document.new
# Image only added to PDF once though used multiple times
canvas = doc.pages.add.canvas
canvas.image(file, at: [100, 500]) # auto-size based on image size
canvas.image(file, at: [100, 300], width: 100) # height based on w/h ratio
canvas.image(file, at: [300, 300], height: 100) # width based on w/h ratio
canvas.image(file, at: [100, 100], width: 300, height: 100)

HexaPDF::Composer.create('images.pdf') do |composer|
  composer.image(file) # fill current rectangular region
  composer.image(file, width: 100)  # height based on w/h ratio
  composer.image(file, height: 100) # width based on w/h ratio
  composer.image(file, width: 300, height: 100)

  # Add the page created above as second page
  composer.document.pages << composer.document.import(doc.pages[0])
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
hexapdf-1.2.0 examples/023-images.rb
hexapdf-1.1.1 examples/023-images.rb
hexapdf-1.1.0 examples/023-images.rb
hexapdf-1.0.3 examples/023-images.rb
hexapdf-1.0.2 examples/023-images.rb
hexapdf-1.0.1 examples/023-images.rb
hexapdf-1.0.0 examples/023-images.rb
hexapdf-0.47.0 examples/023-images.rb
hexapdf-0.46.0 examples/023-images.rb
hexapdf-0.45.0 examples/023-images.rb
hexapdf-0.44.0 examples/023-images.rb
hexapdf-0.41.0 examples/023-images.rb
hexapdf-0.40.0 examples/023-images.rb
hexapdf-0.39.1 examples/023-images.rb
hexapdf-0.39.0 examples/023-images.rb
hexapdf-0.38.0 examples/023-images.rb
hexapdf-0.37.2 examples/023-images.rb
hexapdf-0.37.1 examples/023-images.rb
hexapdf-0.37.0 examples/023-images.rb
hexapdf-0.36.0 examples/023-images.rb