poppler 2.2.4-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +35 -0
- data/Rakefile +75 -0
- data/ext/poppler/depend +6 -0
- data/ext/poppler/extconf.rb +70 -0
- data/ext/poppler/poppler.def +2 -0
- data/ext/poppler/rbpoppler-action.c +372 -0
- data/ext/poppler/rbpoppler-annotation-callout-line.c +127 -0
- data/ext/poppler/rbpoppler-annotation-free-text.c +46 -0
- data/ext/poppler/rbpoppler-annotation-mapping.c +72 -0
- data/ext/poppler/rbpoppler-annotation-markup.c +98 -0
- data/ext/poppler/rbpoppler-annotation-text.c +53 -0
- data/ext/poppler/rbpoppler-annotation.c +74 -0
- data/ext/poppler/rbpoppler-attachment.c +124 -0
- data/ext/poppler/rbpoppler-button-field.c +56 -0
- data/ext/poppler/rbpoppler-choice-field.c +131 -0
- data/ext/poppler/rbpoppler-color.c +107 -0
- data/ext/poppler/rbpoppler-document.c +224 -0
- data/ext/poppler/rbpoppler-font-info.c +59 -0
- data/ext/poppler/rbpoppler-fonts-iter.c +127 -0
- data/ext/poppler/rbpoppler-form-field-mapping.c +44 -0
- data/ext/poppler/rbpoppler-form-field.c +98 -0
- data/ext/poppler/rbpoppler-image-mapping.c +48 -0
- data/ext/poppler/rbpoppler-index-iter.c +128 -0
- data/ext/poppler/rbpoppler-link-mapping.c +47 -0
- data/ext/poppler/rbpoppler-page-transition.c +59 -0
- data/ext/poppler/rbpoppler-page.c +322 -0
- data/ext/poppler/rbpoppler-private.h +77 -0
- data/ext/poppler/rbpoppler-ps-file.c +66 -0
- data/ext/poppler/rbpoppler-rectangle.c +92 -0
- data/ext/poppler/rbpoppler-text-field.c +91 -0
- data/ext/poppler/rbpoppler.c +111 -0
- data/ext/poppler/rbpoppler.h +61 -0
- data/ext/poppler/rbpopplerconversions.h +105 -0
- data/extconf.rb +49 -0
- data/lib/2.0/poppler.so +0 -0
- data/lib/2.1/poppler.so +0 -0
- data/lib/2.2/poppler.so +0 -0
- data/lib/poppler.rb +105 -0
- data/sample/number-pdf.rb +32 -0
- data/sample/pdf2.rb +132 -0
- data/sample/pdf2svg.rb +26 -0
- data/sample/pdf2text.rb +16 -0
- data/sample/pdfcrop.rb +32 -0
- data/sample/pdfdiv.rb +36 -0
- data/test/fixtures/image.pdf +0 -0
- data/test/fixtures/image.png +0 -0
- data/test/poppler-test-utils.rb +58 -0
- data/test/run-test.rb +32 -0
- data/test/test_annotation.rb +86 -0
- data/test/test_color.rb +26 -0
- data/test/test_constants.rb +30 -0
- data/test/test_document.rb +41 -0
- data/test/test_page.rb +42 -0
- data/vendor/local/bin/cjpeg.exe +0 -0
- data/vendor/local/bin/djpeg.exe +0 -0
- data/vendor/local/bin/jpegtran.exe +0 -0
- data/vendor/local/bin/libjpeg-9.dll +0 -0
- data/vendor/local/bin/libpoppler-48.dll +0 -0
- data/vendor/local/bin/libpoppler-cpp-0.dll +0 -0
- data/vendor/local/bin/libpoppler-glib-8.dll +0 -0
- data/vendor/local/bin/libsqlite3-0.dll +0 -0
- data/vendor/local/bin/pdfdetach.exe +0 -0
- data/vendor/local/bin/pdffonts.exe +0 -0
- data/vendor/local/bin/pdfimages.exe +0 -0
- data/vendor/local/bin/pdfinfo.exe +0 -0
- data/vendor/local/bin/pdfseparate.exe +0 -0
- data/vendor/local/bin/pdftocairo.exe +0 -0
- data/vendor/local/bin/pdftohtml.exe +0 -0
- data/vendor/local/bin/pdftoppm.exe +0 -0
- data/vendor/local/bin/pdftops.exe +0 -0
- data/vendor/local/bin/pdftotext.exe +0 -0
- data/vendor/local/bin/pdfunite.exe +0 -0
- data/vendor/local/bin/rdjpgcom.exe +0 -0
- data/vendor/local/bin/sqlite3.exe +0 -0
- data/vendor/local/bin/wrjpgcom.exe +0 -0
- data/vendor/local/include/jconfig.h +60 -0
- data/vendor/local/include/jerror.h +304 -0
- data/vendor/local/include/jmorecfg.h +446 -0
- data/vendor/local/include/jpeglib.h +1180 -0
- data/vendor/local/include/poppler/cpp/poppler-document.h +104 -0
- data/vendor/local/include/poppler/cpp/poppler-embedded-file.h +55 -0
- data/vendor/local/include/poppler/cpp/poppler-font.h +91 -0
- data/vendor/local/include/poppler/cpp/poppler-global.h +111 -0
- data/vendor/local/include/poppler/cpp/poppler-image.h +71 -0
- data/vendor/local/include/poppler/cpp/poppler-page-renderer.h +66 -0
- data/vendor/local/include/poppler/cpp/poppler-page-transition.h +82 -0
- data/vendor/local/include/poppler/cpp/poppler-page.h +76 -0
- data/vendor/local/include/poppler/cpp/poppler-rectangle.h +84 -0
- data/vendor/local/include/poppler/cpp/poppler-toc.h +74 -0
- data/vendor/local/include/poppler/cpp/poppler-version.h +39 -0
- data/vendor/local/include/poppler/glib/poppler-action.h +316 -0
- data/vendor/local/include/poppler/glib/poppler-annot.h +296 -0
- data/vendor/local/include/poppler/glib/poppler-attachment.h +87 -0
- data/vendor/local/include/poppler/glib/poppler-date.h +30 -0
- data/vendor/local/include/poppler/glib/poppler-document.h +299 -0
- data/vendor/local/include/poppler/glib/poppler-enums.h +116 -0
- data/vendor/local/include/poppler/glib/poppler-features.h +88 -0
- data/vendor/local/include/poppler/glib/poppler-form-field.h +111 -0
- data/vendor/local/include/poppler/glib/poppler-layer.h +43 -0
- data/vendor/local/include/poppler/glib/poppler-media.h +73 -0
- data/vendor/local/include/poppler/glib/poppler-movie.h +42 -0
- data/vendor/local/include/poppler/glib/poppler-page.h +377 -0
- data/vendor/local/include/poppler/glib/poppler-structure-element.h +357 -0
- data/vendor/local/include/poppler/glib/poppler.h +250 -0
- data/vendor/local/include/sqlite3.h +7494 -0
- data/vendor/local/include/sqlite3ext.h +487 -0
- data/vendor/local/lib/girepository-1.0/Poppler-0.18.typelib +0 -0
- data/vendor/local/lib/libjpeg.a +0 -0
- data/vendor/local/lib/libjpeg.dll.a +0 -0
- data/vendor/local/lib/libjpeg.la +41 -0
- data/vendor/local/lib/libpoppler-cpp.a +0 -0
- data/vendor/local/lib/libpoppler-cpp.dll.a +0 -0
- data/vendor/local/lib/libpoppler-cpp.la +41 -0
- data/vendor/local/lib/libpoppler-glib.a +0 -0
- data/vendor/local/lib/libpoppler-glib.dll.a +0 -0
- data/vendor/local/lib/libpoppler-glib.la +41 -0
- data/vendor/local/lib/libpoppler.a +0 -0
- data/vendor/local/lib/libpoppler.dll.a +0 -0
- data/vendor/local/lib/libpoppler.la +41 -0
- data/vendor/local/lib/libsqlite3.a +0 -0
- data/vendor/local/lib/libsqlite3.dll.a +0 -0
- data/vendor/local/lib/libsqlite3.la +41 -0
- data/vendor/local/lib/pkgconfig/poppler-cairo.pc +9 -0
- data/vendor/local/lib/pkgconfig/poppler-cpp.pc +13 -0
- data/vendor/local/lib/pkgconfig/poppler-glib.pc +13 -0
- data/vendor/local/lib/pkgconfig/poppler-splash.pc +9 -0
- data/vendor/local/lib/pkgconfig/poppler.pc +11 -0
- data/vendor/local/lib/pkgconfig/sqlite3.pc +13 -0
- data/vendor/local/share/gir-1.0/Poppler-0.18.gir +8281 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerAnnot.html +3221 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerAttachment.html +267 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerDocument.html +3328 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerFormField.html +1403 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerLayer.html +307 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerMedia.html +381 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerMovie.html +197 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerPage.html +3002 -0
- data/vendor/local/share/gtk-doc/html/poppler/PopplerStructureElement.html +3781 -0
- data/vendor/local/share/gtk-doc/html/poppler/annotation-glossary.html +63 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-12.html +123 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-14.html +102 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-16.html +180 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-18.html +72 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-20.html +39 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-0-22.html +64 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-deprecated.html +39 -0
- data/vendor/local/share/gtk-doc/html/poppler/api-index-full.html +1830 -0
- data/vendor/local/share/gtk-doc/html/poppler/ch01.html +74 -0
- data/vendor/local/share/gtk-doc/html/poppler/home.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/index.html +85 -0
- data/vendor/local/share/gtk-doc/html/poppler/index.sgml +557 -0
- data/vendor/local/share/gtk-doc/html/poppler/left-insensitive.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/left.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler-PDF-Utility-functions.html +107 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler-PopplerAction.html +796 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler-PopplerColor.html +201 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler-Version-and-Features-Information.html +254 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler-poppler.html +169 -0
- data/vendor/local/share/gtk-doc/html/poppler/poppler.devhelp2 +470 -0
- data/vendor/local/share/gtk-doc/html/poppler/right-insensitive.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/right.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/style.css +476 -0
- data/vendor/local/share/gtk-doc/html/poppler/up-insensitive.png +0 -0
- data/vendor/local/share/gtk-doc/html/poppler/up.png +0 -0
- data/vendor/local/share/license/poppler/AUTHORS +5 -0
- data/vendor/local/share/license/poppler/COPYING +339 -0
- data/vendor/local/share/man/man1/cjpeg.1 +387 -0
- data/vendor/local/share/man/man1/djpeg.1 +252 -0
- data/vendor/local/share/man/man1/jpegtran.1 +293 -0
- data/vendor/local/share/man/man1/pdfdetach.1 +86 -0
- data/vendor/local/share/man/man1/pdffonts.1 +119 -0
- data/vendor/local/share/man/man1/pdfimages.1 +260 -0
- data/vendor/local/share/man/man1/pdfinfo.1 +152 -0
- data/vendor/local/share/man/man1/pdfseparate.1 +49 -0
- data/vendor/local/share/man/man1/pdftocairo.1 +295 -0
- data/vendor/local/share/man/man1/pdftohtml.1 +107 -0
- data/vendor/local/share/man/man1/pdftoppm.1 +170 -0
- data/vendor/local/share/man/man1/pdftops.1 +217 -0
- data/vendor/local/share/man/man1/pdftotext.1 +137 -0
- data/vendor/local/share/man/man1/pdfunite.1 +33 -0
- data/vendor/local/share/man/man1/rdjpgcom.1 +63 -0
- data/vendor/local/share/man/man1/sqlite3.1 +279 -0
- data/vendor/local/share/man/man1/wrjpgcom.1 +103 -0
- metadata +254 -0
data/extconf.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'mkmf'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
package = "poppler"
|
9
|
+
|
10
|
+
base_dir = Pathname(__FILE__).dirname.expand_path
|
11
|
+
ext_dir = base_dir + "ext" + package
|
12
|
+
mkmf_gnome2_dir = base_dir + 'lib'
|
13
|
+
|
14
|
+
ruby = File.join(RbConfig::CONFIG['bindir'],
|
15
|
+
RbConfig::CONFIG['ruby_install_name'] +
|
16
|
+
RbConfig::CONFIG["EXEEXT"])
|
17
|
+
|
18
|
+
build_dir = Pathname("ext") + package
|
19
|
+
FileUtils.mkdir_p(build_dir.to_s) unless build_dir.exist?
|
20
|
+
extconf_rb_path = ext_dir + "extconf.rb"
|
21
|
+
system(ruby, "-C", build_dir.to_s, extconf_rb_path.to_s, *ARGV) || exit(false)
|
22
|
+
|
23
|
+
create_makefile(package)
|
24
|
+
FileUtils.mv("Makefile", "Makefile.lib")
|
25
|
+
|
26
|
+
File.open("Makefile", "w") do |makefile|
|
27
|
+
makefile.puts(<<-EOM)
|
28
|
+
all:
|
29
|
+
(cd ext/#{package} && $(MAKE))
|
30
|
+
$(MAKE) -f Makefile.lib
|
31
|
+
|
32
|
+
install:
|
33
|
+
(cd ext/#{package} && $(MAKE) install)
|
34
|
+
$(MAKE) -f Makefile.lib install
|
35
|
+
|
36
|
+
site-install:
|
37
|
+
(cd ext/#{package} && $(MAKE) site-install)
|
38
|
+
$(MAKE) -f Makefile.lib site-install
|
39
|
+
|
40
|
+
clean:
|
41
|
+
(cd ext/#{package} && $(MAKE) clean)
|
42
|
+
$(MAKE) -f Makefile.lib clean
|
43
|
+
|
44
|
+
distclean:
|
45
|
+
(cd ext/#{package} && $(MAKE) distclean)
|
46
|
+
$(MAKE) -f Makefile.lib distclean
|
47
|
+
@rm -f Makefile.lib
|
48
|
+
EOM
|
49
|
+
end
|
data/lib/2.0/poppler.so
ADDED
Binary file
|
data/lib/2.1/poppler.so
ADDED
Binary file
|
data/lib/2.2/poppler.so
ADDED
Binary file
|
data/lib/poppler.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Copyright(C) 2006-2009 Ruby-GNOME2 Project.
|
2
|
+
#
|
3
|
+
# This library is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 2.1 of the License.
|
6
|
+
#
|
7
|
+
# Foobar is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10
|
+
# GNU Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public License
|
13
|
+
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
14
|
+
|
15
|
+
require "tempfile"
|
16
|
+
require "date"
|
17
|
+
require "glib2"
|
18
|
+
require "gdk_pixbuf2"
|
19
|
+
require "cairo"
|
20
|
+
|
21
|
+
base_dir = Pathname.new(__FILE__).dirname.dirname.expand_path
|
22
|
+
vendor_dir = base_dir + "vendor" + "local"
|
23
|
+
vendor_bin_dir = vendor_dir + "bin"
|
24
|
+
GLib.prepend_dll_path(vendor_bin_dir)
|
25
|
+
begin
|
26
|
+
major, minor, = RUBY_VERSION.split(/\./)
|
27
|
+
require "#{major}.#{minor}/poppler.so"
|
28
|
+
rescue LoadError
|
29
|
+
require "poppler.so"
|
30
|
+
end
|
31
|
+
|
32
|
+
module Poppler
|
33
|
+
LOG_DOMAIN = "Poppler"
|
34
|
+
|
35
|
+
VERSION = version.split(".").collect {|x| x.to_i}
|
36
|
+
|
37
|
+
class Document
|
38
|
+
private
|
39
|
+
def pdf_data?(data)
|
40
|
+
/\A%PDF-1\.\d/ =~ data
|
41
|
+
end
|
42
|
+
|
43
|
+
def ensure_uri(uri)
|
44
|
+
if pdf_data?(uri)
|
45
|
+
@pdf = Tempfile.new("ruby-poppler-pdf")
|
46
|
+
@pdf.binmode
|
47
|
+
@pdf.print(uri)
|
48
|
+
@pdf.close
|
49
|
+
uri = @pdf.path
|
50
|
+
end
|
51
|
+
|
52
|
+
if GLib.path_is_absolute?(uri)
|
53
|
+
GLib.filename_to_uri(uri)
|
54
|
+
elsif /\A[a-zA-Z][a-zA-Z\d\-+.]*:/.match(uri)
|
55
|
+
uri
|
56
|
+
else
|
57
|
+
GLib.filename_to_uri(File.expand_path(uri))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if defined?(TextField)
|
63
|
+
class TextField
|
64
|
+
def multiline?
|
65
|
+
type == FormTextType::MULTILINE
|
66
|
+
end
|
67
|
+
|
68
|
+
def file_select?
|
69
|
+
type == FormTextType::FILE_SELECT
|
70
|
+
end
|
71
|
+
|
72
|
+
def normal?
|
73
|
+
type == FormTextType::NORMAL
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if defined?(ChoiceField)
|
79
|
+
class ChoiceField
|
80
|
+
def combo?
|
81
|
+
type == FormChioceType::COMBO
|
82
|
+
end
|
83
|
+
|
84
|
+
def list?
|
85
|
+
type == FormChoiceType::LIST
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if Poppler.cairo_available?
|
92
|
+
module Cairo
|
93
|
+
class Context
|
94
|
+
def render_poppler_page(page, *args, &block)
|
95
|
+
page.render(self, *args, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
def render_poppler_page_selection(page, *args, &block)
|
99
|
+
page.render_selection(self, *args, &block)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
GLib::Log.set_log_domain(Poppler::LOG_DOMAIN)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'poppler'
|
4
|
+
|
5
|
+
input = ARGV.first
|
6
|
+
output = input.sub(/\.pdf$/, "-numbered.pdf")
|
7
|
+
|
8
|
+
doc = Poppler::Document.new(input)
|
9
|
+
first_page = doc[0]
|
10
|
+
|
11
|
+
Cairo::PDFSurface.new(output, *first_page.size) do |surface|
|
12
|
+
context = Cairo::Context.new(surface)
|
13
|
+
|
14
|
+
doc.each_with_index do |page, i|
|
15
|
+
width, height = page.size
|
16
|
+
surface.set_size(width, height)
|
17
|
+
context.save do
|
18
|
+
context.render_poppler_page(page)
|
19
|
+
end
|
20
|
+
context.save do
|
21
|
+
layout = context.create_pango_layout
|
22
|
+
layout.text = i.to_s
|
23
|
+
layout.width = width * Pango::SCALE
|
24
|
+
layout.alignment = Pango::Layout::ALIGN_CENTER
|
25
|
+
layout.font_description = Pango::FontDescription.new("Sans 288")
|
26
|
+
context.move_to(0, (height - layout.pixel_size[1]) / 2.0)
|
27
|
+
context.set_source_rgba(0.1, 0.1, 0.1, 0.5)
|
28
|
+
context.show_pango_layout(layout)
|
29
|
+
end
|
30
|
+
context.show_page
|
31
|
+
end
|
32
|
+
end
|
data/sample/pdf2.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "tempfile"
|
4
|
+
require "optparse"
|
5
|
+
require "poppler"
|
6
|
+
require "gdk_pixbuf2"
|
7
|
+
|
8
|
+
page = 0
|
9
|
+
scale = 1.0
|
10
|
+
rotate = 0
|
11
|
+
|
12
|
+
parser = OptionParser.new
|
13
|
+
parser.banner = <<-BANNER
|
14
|
+
Usage: #{parser.program_name} INPUT.PDF OUTPUT [options]
|
15
|
+
|
16
|
+
#{parser.program_name} coverts the target page in INPUT.PDF to an image file.
|
17
|
+
Many popular image formats such as PNG and JPEG are supported.
|
18
|
+
You can specify output image format by OUTPUT file extension.
|
19
|
+
For example, the following comand generates PNG file:
|
20
|
+
|
21
|
+
% #{$0} INPUT.PDF OUTPUT.png
|
22
|
+
|
23
|
+
BANNER
|
24
|
+
|
25
|
+
parser.on("--page=PAGE", Integer,
|
26
|
+
"Use PAGE as the target page",
|
27
|
+
"(0-origin)",
|
28
|
+
"[#{page}]") do |value|
|
29
|
+
page = value.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on("--scale=RATIO", Float,
|
33
|
+
"Scale the target page in INPUT.PDF RATIO times larger in OUTPUT",
|
34
|
+
"[#{scale}]") do |value|
|
35
|
+
scale = value.to_f
|
36
|
+
end
|
37
|
+
|
38
|
+
parser.on("--rotate=DEGREE", Integer,
|
39
|
+
"Rotate the target page in INPUT.PDF DEGREE degrees clockwise in OUTPUT",
|
40
|
+
"(available values: 0...360)",
|
41
|
+
"[#{rotate}]") do |value|
|
42
|
+
rotate = value.to_i % 360
|
43
|
+
end
|
44
|
+
|
45
|
+
rest_args = parser.parse!
|
46
|
+
if rest_args.size != 2
|
47
|
+
puts(parser.help)
|
48
|
+
exit(false)
|
49
|
+
end
|
50
|
+
input, output = rest_args
|
51
|
+
|
52
|
+
ext_name = File.extname(output)[1..-1]
|
53
|
+
if ext_name
|
54
|
+
output_type = ext_name.downcase
|
55
|
+
output_type = "jpeg" if /jpg/ =~ output_type
|
56
|
+
else
|
57
|
+
output_type = "png"
|
58
|
+
end
|
59
|
+
|
60
|
+
def compute_size(width, height, rotate)
|
61
|
+
width = width.to_f
|
62
|
+
height = height.to_f
|
63
|
+
radius = 0
|
64
|
+
unless rotate.zero?
|
65
|
+
radius = rotate / 180.0 * Math::PI
|
66
|
+
if (90 < rotate and rotate < 180) or
|
67
|
+
(270 < rotate and rotate < 360)
|
68
|
+
radius -= Math::PI / 2
|
69
|
+
end
|
70
|
+
end
|
71
|
+
inner_angle1 = Math.atan(width / height)
|
72
|
+
inner_angle2 = Math.atan(height / width)
|
73
|
+
diagonal = Math.sqrt(width ** 2 + height ** 2)
|
74
|
+
|
75
|
+
angle1 = radius + inner_angle1
|
76
|
+
angle2 = radius + inner_angle2
|
77
|
+
|
78
|
+
bottom1 = diagonal * Math.cos(angle1)
|
79
|
+
length1 = (bottom1 * Math.tan(angle1)).abs.to_i
|
80
|
+
bottom2 = diagonal * Math.cos(angle2)
|
81
|
+
length2 = (bottom2 * Math.tan(angle2)).abs.to_i
|
82
|
+
|
83
|
+
if (0 <= rotate and rotate <= 90) or
|
84
|
+
(180 <= rotate and rotate <= 270)
|
85
|
+
[length1, length2]
|
86
|
+
else
|
87
|
+
[length2, length1]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_pixbuf_with_cairo(input, page_number, scale, rotate)
|
92
|
+
doc = Poppler::Document.new(input)
|
93
|
+
page = doc[page_number]
|
94
|
+
width, height = page.size.collect {|x| x * scale}
|
95
|
+
surface_width, surface_height = compute_size(width, height, rotate)
|
96
|
+
|
97
|
+
surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32,
|
98
|
+
surface_width, surface_height)
|
99
|
+
cr = Cairo::Context.new(surface)
|
100
|
+
|
101
|
+
half_width = surface_width / 2.0
|
102
|
+
half_height = surface_height / 2.0
|
103
|
+
cr.translate(half_width, half_height)
|
104
|
+
cr.rotate(rotate / 180.0 * Math::PI)
|
105
|
+
cr.translate(-half_width, -half_height)
|
106
|
+
|
107
|
+
cr.translate((surface_width - width) / 2.0,
|
108
|
+
(surface_height - height) / 2.0)
|
109
|
+
cr.set_source_rgb(1, 1, 1)
|
110
|
+
cr.rectangle(0, 0, width, height)
|
111
|
+
cr.fill
|
112
|
+
|
113
|
+
cr.scale(scale, scale)
|
114
|
+
cr.render_poppler_page(page)
|
115
|
+
temp = Tempfile.new("pdf2")
|
116
|
+
cr.target.write_to_png(temp.path)
|
117
|
+
cr.target.finish
|
118
|
+
Gdk::Pixbuf.new(temp.path)
|
119
|
+
end
|
120
|
+
|
121
|
+
unless Poppler.cairo_available?
|
122
|
+
puts "cairo isn't available."
|
123
|
+
exit(false)
|
124
|
+
end
|
125
|
+
pixbuf = to_pixbuf_with_cairo(input, page, scale, rotate)
|
126
|
+
|
127
|
+
if pixbuf.nil?
|
128
|
+
puts "Is it a PDF file?: #{input}"
|
129
|
+
exit(-1)
|
130
|
+
end
|
131
|
+
puts "saving to #{output}(#{pixbuf.width}x#{pixbuf.height})..."
|
132
|
+
pixbuf.save(output, output_type)
|
data/sample/pdf2svg.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "poppler"
|
4
|
+
|
5
|
+
if ARGV.size < 1
|
6
|
+
puts "usage: #{$0} input.pdf"
|
7
|
+
exit(-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
input, = ARGV
|
11
|
+
|
12
|
+
output = input.sub(/\..+$/, ".svg")
|
13
|
+
output = "#{output}.svg" if input == output
|
14
|
+
|
15
|
+
doc = Poppler::Document.new(input)
|
16
|
+
|
17
|
+
width, height = doc.pages[0].size
|
18
|
+
Cairo::SVGSurface.new(output, width, height) do |surface|
|
19
|
+
surface.restrict_to_version("1_2")
|
20
|
+
|
21
|
+
context = Cairo::Context.new(surface)
|
22
|
+
doc.each do |page|
|
23
|
+
page.render(context)
|
24
|
+
context.show_page
|
25
|
+
end
|
26
|
+
end
|
data/sample/pdf2text.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "poppler"
|
4
|
+
|
5
|
+
if ARGV.size < 1
|
6
|
+
puts "usage: #{$0} input.pdf"
|
7
|
+
exit(-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
input = ARGV.shift
|
11
|
+
input_uri = "file://#{File.expand_path(input)}"
|
12
|
+
|
13
|
+
doc = Poppler::Document.new(input_uri)
|
14
|
+
doc.each do |page|
|
15
|
+
puts page.get_text
|
16
|
+
end
|
data/sample/pdfcrop.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "poppler"
|
4
|
+
|
5
|
+
if ARGV.size != 2
|
6
|
+
puts "usage: #{$0} input.pdf output.pdf"
|
7
|
+
exit(-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
input, output = ARGV
|
11
|
+
|
12
|
+
doc = Poppler::Document.new(input)
|
13
|
+
|
14
|
+
width, height = doc.pages[0].size
|
15
|
+
x_margin = width * 0.1
|
16
|
+
y_margin = height * 0.1
|
17
|
+
croped_width = width - (2 * x_margin)
|
18
|
+
croped_height = height - (2 * y_margin)
|
19
|
+
Cairo::PDFSurface.new(output, croped_width, croped_height) do |surface|
|
20
|
+
context = Cairo::Context.new(surface)
|
21
|
+
|
22
|
+
doc.each do |page|
|
23
|
+
width, height = page.size
|
24
|
+
context.save do
|
25
|
+
context.translate(-x_margin, -y_margin)
|
26
|
+
context.rectangle(x_margin, y_margin, croped_width, croped_height)
|
27
|
+
context.clip
|
28
|
+
page.render(context)
|
29
|
+
context.show_page
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/sample/pdfdiv.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "poppler"
|
4
|
+
|
5
|
+
if ARGV.size != 2
|
6
|
+
puts "usage: #{$0} input.pdf output.pdf"
|
7
|
+
exit(-1)
|
8
|
+
end
|
9
|
+
|
10
|
+
input, output = ARGV
|
11
|
+
|
12
|
+
doc = Poppler::Document.new(input)
|
13
|
+
|
14
|
+
width, height = doc.pages[0].size
|
15
|
+
Cairo::PDFSurface.new(output, width / 2, height) do |surface|
|
16
|
+
context = Cairo::Context.new(surface)
|
17
|
+
|
18
|
+
doc.each do |page|
|
19
|
+
width, height = page.size
|
20
|
+
half_width = width / 2
|
21
|
+
context.save do
|
22
|
+
context.rectangle(0, 0, half_width, height)
|
23
|
+
context.clip
|
24
|
+
page.render(context)
|
25
|
+
context.show_page
|
26
|
+
end
|
27
|
+
|
28
|
+
context.save do
|
29
|
+
context.translate(-half_width, 0)
|
30
|
+
context.rectangle(half_width, 0, half_width, height)
|
31
|
+
context.clip
|
32
|
+
page.render(context)
|
33
|
+
context.show_page
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
Binary file
|
Binary file
|