pdflib_mini 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +160 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pdflib_mini.rb +38 -0
- data/lib/pdflib_mini/handle.rb +4 -0
- data/lib/pdflib_mini/handle/action.rb +10 -0
- data/lib/pdflib_mini/handle/asset.rb +10 -0
- data/lib/pdflib_mini/handle/base.rb +16 -0
- data/lib/pdflib_mini/handle/bookmark.rb +10 -0
- data/lib/pdflib_mini/handle/color.rb +10 -0
- data/lib/pdflib_mini/handle/data3d.rb +10 -0
- data/lib/pdflib_mini/handle/data3d_view.rb +10 -0
- data/lib/pdflib_mini/handle/folder.rb +22 -0
- data/lib/pdflib_mini/handle/font.rb +42 -0
- data/lib/pdflib_mini/handle/graphics.rb +39 -0
- data/lib/pdflib_mini/handle/graphics_state.rb +16 -0
- data/lib/pdflib_mini/handle/image.rb +39 -0
- data/lib/pdflib_mini/handle/item.rb +22 -0
- data/lib/pdflib_mini/handle/layer.rb +17 -0
- data/lib/pdflib_mini/handle/path.rb +45 -0
- data/lib/pdflib_mini/handle/pattern.rb +16 -0
- data/lib/pdflib_mini/handle/pdf.rb +6 -0
- data/lib/pdflib_mini/handle/pdf/document.rb +51 -0
- data/lib/pdflib_mini/handle/pdf/page.rb +72 -0
- data/lib/pdflib_mini/handle/profile.rb +10 -0
- data/lib/pdflib_mini/handle/shading.rb +16 -0
- data/lib/pdflib_mini/handle/table_cell.rb +39 -0
- data/lib/pdflib_mini/handle/template.rb +16 -0
- data/lib/pdflib_mini/handle/textflow.rb +42 -0
- data/lib/pdflib_mini/handle/textline.rb +33 -0
- data/lib/pdflib_mini/info.rb +237 -0
- data/lib/pdflib_mini/info_reader.rb +54 -0
- data/lib/pdflib_mini/pdflib.rb +457 -0
- data/lib/pdflib_mini/version.rb +3 -0
- data/pdflib_mini.gemspec +28 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac6c70a4f3d759d36b442cae5f7a9ff26f876bc3
|
4
|
+
data.tar.gz: 8f4a353c22262f01ac88fff07ff7d8c185638468
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 09d93ee6c6a8d68734dce4283716d91d6497838a6917fac45f0ed15c6b8a77e50b65f2746d891fb87e1b000e68db3de6cb68f40967d0bfa38d2b2ac8a8f00ee5
|
7
|
+
data.tar.gz: 90810954a8fe0fef5bc9461ef14096dad36e0451c85dd3d0bc6fb5edc718aa720d507c25380db99f317475ca29d349ceb2a28454694ddaa6294a3814c43bb47f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at trot.thunder@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Takumi IINO
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# PdflibMini
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/pdflib_mini.svg)](http://badge.fury.io/rb/pdflib_mini)
|
4
|
+
[![Build Status](https://travis-ci.org/troter/pdflib_mini.svg?branch=master)](https://travis-ci.org/troter/pdflib_mini)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/troter/pdflib_mini/badge.svg)](https://coveralls.io/r/troter/pdflib_mini)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/troter/pdflib_mini/badges/gpa.svg)](https://codeclimate.com/github/troter/pdflib_mini)
|
7
|
+
|
8
|
+
PdflibMini is a mini wrapper for PDFlib. this provides useful methods and some extension point.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'pdflib_mini'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install pdflib_mini
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Require PDFlib and this gem, and replace PDFlib by PDFlibMini.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require './PDFlib'
|
32
|
+
require 'pdflib_mini'
|
33
|
+
|
34
|
+
# p = PDFlib.new
|
35
|
+
p = PDFlibMini.new
|
36
|
+
```
|
37
|
+
|
38
|
+
PdflibMini does not break the interface of PDFlib.
|
39
|
+
|
40
|
+
## Handle object
|
41
|
+
|
42
|
+
PdflibMini returns a handle object that wrapping PDFlib's handle in most cases.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
p = PDFlilbMini.new
|
46
|
+
p.load_font("Helvetica", "unicode", '').class # => PdflibMini::Handle::Font
|
47
|
+
p.load_image('auto', imagefile, '').class # => PdflibMini::Handle::Image
|
48
|
+
p.open_pdi_document(infile, '').class # => PdflibMini::Handle::Pdf::Document
|
49
|
+
```
|
50
|
+
|
51
|
+
### Easy access to information for handle object
|
52
|
+
|
53
|
+
Handle object has reader methods there easy access to information for itself.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# raw (float) values
|
57
|
+
doc = p.open_pdi_document(infile, '')
|
58
|
+
page = doc.open_pdi_page(1, '')
|
59
|
+
page.pagewidth
|
60
|
+
page.pageheight
|
61
|
+
|
62
|
+
# string values
|
63
|
+
image = p.load_image('auto', imagefile, '')
|
64
|
+
image.filename
|
65
|
+
image.imagetype
|
66
|
+
|
67
|
+
font = p.load_font('Helvetica', 'unicode', '')
|
68
|
+
font.feature('name=liga')
|
69
|
+
font.featurelist
|
70
|
+
|
71
|
+
# handle object
|
72
|
+
font.clippingpath # PdflibMini::Handle::Path instance
|
73
|
+
|
74
|
+
# boolean
|
75
|
+
font.hostfont
|
76
|
+
font.symbolfont? # more ruby-ish
|
77
|
+
|
78
|
+
# conversion
|
79
|
+
font.clippingpath(as: :path) # PdflibMini::Handle::Path instance
|
80
|
+
font.clippingpath(as: :raw) # float (PDFlib's handle)
|
81
|
+
image.imagetype # string
|
82
|
+
image.imagetype(as: :raw) # float (PDFlib's string index)
|
83
|
+
```
|
84
|
+
|
85
|
+
### Handle specific methods.
|
86
|
+
|
87
|
+
Handle object has some method like `fit_xxx`, `info_xxx`, and `fit_xxxblock`.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
doc = p.open_pdi_document(infile, '')
|
91
|
+
page = doc.open_pdi_page(1, '')
|
92
|
+
page.fit_pdi_page(0, 0, '')
|
93
|
+
|
94
|
+
image = p.load_image('auto', imagefile, '')
|
95
|
+
image.info_image('imagewidth', '')
|
96
|
+
```
|
97
|
+
|
98
|
+
### Extension point
|
99
|
+
|
100
|
+
Handle object is not singleton. it can be easily extended.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
image = p.load_image('auto', imagefile, '')
|
104
|
+
|
105
|
+
module ImagePathname
|
106
|
+
def filename(*args)
|
107
|
+
Pathname(super(*args))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# extend each instance
|
112
|
+
image.extend ImagePathname
|
113
|
+
|
114
|
+
# or prepend module
|
115
|
+
module PdflibMini
|
116
|
+
module Handle
|
117
|
+
class Image
|
118
|
+
prepend ImagePathname
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
image.filename.expand_path
|
124
|
+
```
|
125
|
+
|
126
|
+
## Using blocks for scope management
|
127
|
+
|
128
|
+
Passing blocks to begin_xxx, open_xxx, and some other methods.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
p = PDFlilbMini.new
|
132
|
+
p.begin_document(outfile, '') do |result|
|
133
|
+
fail if result == -1
|
134
|
+
p.open_pdi_document(infile, '') do |indoc|
|
135
|
+
fail if indoc == -1
|
136
|
+
indoc.open_pdi_page(1, '') do |inpage|
|
137
|
+
fail if (inpage == -1)
|
138
|
+
p.begin_page_ext(10, 10, '') do
|
139
|
+
inpage.fit_pdi_page(0, 0, '')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
## Development
|
147
|
+
|
148
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
149
|
+
|
150
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
151
|
+
|
152
|
+
## Contributing
|
153
|
+
|
154
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/troter/pdflib_mini. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
155
|
+
|
156
|
+
|
157
|
+
## License
|
158
|
+
|
159
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
160
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pdflib_mini"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/pdflib_mini.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require_relative 'pdflib_mini/info'
|
3
|
+
require_relative 'pdflib_mini/info_reader'
|
4
|
+
require_relative 'pdflib_mini/handle'
|
5
|
+
require_relative 'pdflib_mini/handle/base'
|
6
|
+
require_relative 'pdflib_mini/handle/action'
|
7
|
+
require_relative 'pdflib_mini/handle/asset'
|
8
|
+
require_relative 'pdflib_mini/handle/bookmark'
|
9
|
+
require_relative 'pdflib_mini/handle/color'
|
10
|
+
require_relative 'pdflib_mini/handle/data3d'
|
11
|
+
require_relative 'pdflib_mini/handle/data3d_view'
|
12
|
+
require_relative 'pdflib_mini/handle/folder'
|
13
|
+
require_relative 'pdflib_mini/handle/font'
|
14
|
+
require_relative 'pdflib_mini/handle/graphics'
|
15
|
+
require_relative 'pdflib_mini/handle/image'
|
16
|
+
require_relative 'pdflib_mini/handle/item'
|
17
|
+
require_relative 'pdflib_mini/handle/layer'
|
18
|
+
require_relative 'pdflib_mini/handle/path'
|
19
|
+
require_relative 'pdflib_mini/handle/pattern'
|
20
|
+
require_relative 'pdflib_mini/handle/pdf'
|
21
|
+
require_relative 'pdflib_mini/handle/pdf/document'
|
22
|
+
require_relative 'pdflib_mini/handle/pdf/page'
|
23
|
+
require_relative 'pdflib_mini/handle/profile'
|
24
|
+
require_relative 'pdflib_mini/handle/shading'
|
25
|
+
require_relative 'pdflib_mini/handle/table_cell'
|
26
|
+
require_relative 'pdflib_mini/handle/template'
|
27
|
+
require_relative 'pdflib_mini/handle/textflow'
|
28
|
+
require_relative 'pdflib_mini/handle/textline'
|
29
|
+
require_relative 'pdflib_mini/pdflib'
|
30
|
+
require_relative "pdflib_mini/version"
|
31
|
+
|
32
|
+
module PdflibMini
|
33
|
+
def self.new
|
34
|
+
PdflibMini::Pdflib.new(Kernel.const_get(:PDFlib).new)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
PDFlibMini = PdflibMini
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PdflibMini
|
2
|
+
module Handle
|
3
|
+
class Folder < Base
|
4
|
+
def initialize(folder, p)
|
5
|
+
super(folder)
|
6
|
+
@p = p
|
7
|
+
end
|
8
|
+
|
9
|
+
# 12.6 PDF Packages and Portfolios
|
10
|
+
# int add_portfolio_folder(int parent, string foldername, string optlist)
|
11
|
+
def add_portfolio_folder(*args)
|
12
|
+
@p.add_portfolio_folder(self, *args)
|
13
|
+
end
|
14
|
+
|
15
|
+
# 12.6 PDF Packages and Portfolios
|
16
|
+
# int add_portfolio_file(int folder, string filename, string optlist)
|
17
|
+
def add_portfolio_file(*args)
|
18
|
+
@p.add_portfolio_file(self, *args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|