Sha256: 91f9b9adbb914607ef639f100105efaebf89673d2711f10cb0ac42d48a570585

Contents?: true

Size: 719 Bytes

Versions: 81

Compression:

Stored size: 719 Bytes

Contents

#!/usr/bin/env ruby

require "poppler"

if ARGV.size != 2
  puts "usage: #{$0} input.pdf output.pdf"
  exit(-1)
end

input, output = ARGV

doc = Poppler::Document.new(input)

width, height = doc[0].size
x_margin = width * 0.1
y_margin = height * 0.1
croped_width = width - (2 * x_margin)
croped_height = height - (2 * y_margin)
Cairo::PDFSurface.new(output, croped_width, croped_height) do |surface|
  context = Cairo::Context.new(surface)

  doc.each do |page|
    width, height = page.size
    context.save do
      context.translate(-x_margin, -y_margin)
      context.rectangle(x_margin, y_margin, croped_width, croped_height)
      context.clip
      page.render(context)
      context.show_page
    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
poppler-4.2.5 sample/pdfcrop.rb
poppler-4.2.4 sample/pdfcrop.rb
poppler-4.2.3 sample/pdfcrop.rb
poppler-4.2.2 sample/pdfcrop.rb
poppler-4.2.1 sample/pdfcrop.rb
poppler-4.2.0 sample/pdfcrop.rb
poppler-4.1.9 sample/pdfcrop.rb
poppler-4.1.8 sample/pdfcrop.rb
poppler-4.1.7 sample/pdfcrop.rb
poppler-4.1.6 sample/pdfcrop.rb
poppler-4.1.5 sample/pdfcrop.rb
poppler-4.1.4 sample/pdfcrop.rb
poppler-4.1.3 sample/pdfcrop.rb
poppler-4.1.2 sample/pdfcrop.rb
poppler-4.1.1 sample/pdfcrop.rb
poppler-4.1.0 sample/pdfcrop.rb
poppler-4.0.9 sample/pdfcrop.rb
poppler-4.0.8 sample/pdfcrop.rb
poppler-4.0.7 sample/pdfcrop.rb
poppler-4.0.6 sample/pdfcrop.rb