Sha256: f078e50261ae62ee52581d6fe1a967fdb91e27aae62ef3012bc3afab37a4b9de

Contents?: true

Size: 1.66 KB

Versions: 83

Compression:

Stored size: 1.66 KB

Contents

#!/usr/bin/env ruby
# Copyright (C) 2017  Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# usage :
#   ruby number-pdf.rb example.pdf

require "poppler"
require "pango"

input = ARGV.first
output = input.sub(/\.pdf$/, "-numbered.pdf")

doc = Poppler::Document.new(input)
first_page = doc[0]

Cairo::PDFSurface.new(output, *first_page.size) do |surface|
  context = Cairo::Context.new(surface)

  doc.each_with_index do |page, i|
    width, height = page.size
    surface.set_size(width, height)
    context.save do
      context.render_poppler_page(page)
    end
    context.save do
      layout = context.create_pango_layout
      layout.text = i.to_s
      layout.width = width * Pango::SCALE
      layout.alignment = :center
      layout.font_description = Pango::FontDescription.new("Sans 288")
      context.move_to(0, (height - layout.pixel_size[1]) / 2.0)
      context.set_source_rgba(0.1, 0.1, 0.1, 0.5)
      context.show_pango_layout(layout)
    end
    context.show_page
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
poppler-4.2.7 sample/number-pdf.rb
poppler-4.2.6 sample/number-pdf.rb
poppler-4.2.5 sample/number-pdf.rb
poppler-4.2.4 sample/number-pdf.rb
poppler-4.2.3 sample/number-pdf.rb
poppler-4.2.2 sample/number-pdf.rb
poppler-4.2.1 sample/number-pdf.rb
poppler-4.2.0 sample/number-pdf.rb
poppler-4.1.9 sample/number-pdf.rb
poppler-4.1.8 sample/number-pdf.rb
poppler-4.1.7 sample/number-pdf.rb
poppler-4.1.6 sample/number-pdf.rb
poppler-4.1.5 sample/number-pdf.rb
poppler-4.1.4 sample/number-pdf.rb
poppler-4.1.3 sample/number-pdf.rb
poppler-4.1.2 sample/number-pdf.rb
poppler-4.1.1 sample/number-pdf.rb
poppler-4.1.0 sample/number-pdf.rb
poppler-4.0.9 sample/number-pdf.rb
poppler-4.0.8 sample/number-pdf.rb