workspace-pdf 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/workspace-pdf.rb +63 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 92881b32008263f9c53950a240546d7ab69e3793
|
4
|
+
data.tar.gz: d1c013547ca904b49040454f17767718e9d8dc8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d8d149bcc1c5d5266aab672a6d34749994080eaa407958ce00bd67bb973c11e112917fd4ce8b2910ef32ddf2b90031cfa645e9d7046533ab8fa38da25f32c24
|
7
|
+
data.tar.gz: 2e197a7bba7c538c7b49c6e6bda151f115fb3041cb08e1742562328dbd3ecc3c4d51745aa9409ea05c9d315900442171e5986385f158540dfaeaeab066c4a9b6
|
data/workspace-pdf.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "poppler"
|
2
|
+
|
3
|
+
module Workspace
|
4
|
+
class File
|
5
|
+
def pdf?
|
6
|
+
["pdf"].include?(extension)
|
7
|
+
end
|
8
|
+
|
9
|
+
def pdf
|
10
|
+
Pdf.new(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Pdf
|
14
|
+
attr_reader :file
|
15
|
+
|
16
|
+
def initialize(file)
|
17
|
+
@file = file
|
18
|
+
end
|
19
|
+
|
20
|
+
def pages
|
21
|
+
@doc ||= Poppler::Document.new(@file.to_s)
|
22
|
+
@doc.pages.map { |page| PdfPage.new(self, page) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def export(output_dir, filename: 'page-%03d.png', width: nil, &block)
|
26
|
+
self.pages.each do |page|
|
27
|
+
page.export(output_dir.file(filename % page.index), { width: width }, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class PdfPage
|
33
|
+
attr_reader :pdf, :page, :index
|
34
|
+
|
35
|
+
def initialize(pdf, page)
|
36
|
+
@pdf = pdf
|
37
|
+
@page = page
|
38
|
+
@index = page.index
|
39
|
+
end
|
40
|
+
|
41
|
+
def export(output_file, width: nil, &block)
|
42
|
+
output_width = @page.size[0]
|
43
|
+
output_height = @page.size[1]
|
44
|
+
output_scale = 1.0
|
45
|
+
unless width.nil?
|
46
|
+
output_scale = width / output_width
|
47
|
+
output_width *= output_scale
|
48
|
+
output_height *= output_scale
|
49
|
+
end
|
50
|
+
surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, output_width, output_height)
|
51
|
+
context = Cairo::Context.new(surface)
|
52
|
+
context.set_source_rgb(1, 1, 1)
|
53
|
+
context.paint
|
54
|
+
context.scale(output_scale, output_scale)
|
55
|
+
context.render_poppler_page(@page)
|
56
|
+
yield(context) if block_given?
|
57
|
+
output_file.dir.create unless output_file.dir.exists?
|
58
|
+
surface.write_to_png(output_file.to_s)
|
59
|
+
context.target.finish
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workspace-pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Strebitzer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: workspace
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: poppler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
- - "<="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 3.1.8
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.1'
|
44
|
+
- - "<="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.1.8
|
47
|
+
description: Workspace makes it a breeze to work with files and directories
|
48
|
+
email:
|
49
|
+
- tobias.strebitzer@magloft.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- workspace-pdf.rb
|
55
|
+
homepage: https://github.com/magloft/workspace
|
56
|
+
licenses:
|
57
|
+
- BSD-3-Clause
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- "."
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.4'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.6.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Workspace gem extension to allow transformation and optimization of pdf files
|
79
|
+
test_files: []
|