combine_pdf 0.2.16 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/lib/combine_pdf/fonts.rb +11 -14
- data/lib/combine_pdf/page_methods.rb +32 -0
- data/lib/combine_pdf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a01d7ee2e0bd120239415e5691dc391a22c1e2
|
4
|
+
data.tar.gz: a7719887e8d6b96dfde01100ff3139a8fdcd0376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccdc753817129e63d0d118e955d386d27102b72a4cad9f67681dbaf9a5cf3d271a273f06fd4aa1837dcc0bb5738d12aa6a12125bdb4747b71b2702e40ebfd1b6
|
7
|
+
data.tar.gz: 130f7f1b54e1847d1701ddc5311695e25e85f8cea3d2cd3ef4a253ffbc69565f897add7b1b50f0ccfe18d15f06a44791e154d640c513ae9fecfe49e6cd91c1a6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
Change log v.0.2.17
|
6
|
+
|
7
|
+
**Feature**: added the `page#crop` method to easily crop a PDF file in accordance with the GWG industry association recommendations (updating the `MediaBox` property rather then the `CropBox`). Credit to @wingleungchoi for this feature.
|
8
|
+
|
9
|
+
***
|
10
|
+
|
11
|
+
Change log v.0.2.16
|
12
|
+
|
13
|
+
**Fix**: Fix for issue #49 where specific PDF files containing junk data after the %%EOF marker couldn't be opened (as they were invalid files). The issue was fixed by scanning any trailing data before continuing to parse any PDF file beyond the first %%EOF markers (multiple markers are common when using the PDF format). Credit to @wingleungchoi for providing an example for the issue.
|
14
|
+
|
15
|
+
***
|
16
|
+
|
5
17
|
Change log v.0.2.15
|
6
18
|
|
7
19
|
**Fix**: Fix for issue #22 where specific PDF files with nested references could cause page stamping to fail, raising an exception. Credit to @tomascharad for finding the issue.
|
@@ -44,7 +56,7 @@ Change log v.0.2.10
|
|
44
56
|
|
45
57
|
Change log v.0.2.9
|
46
58
|
|
47
|
-
**Fix** hopefully fixed issue #33 ([NoMethodError undefined method `[]
|
59
|
+
**Fix** hopefully fixed issue #33 ([NoMethodError undefined method `[]` for nil:NilClass](https://github.com/boazsegev/combine_pdf/issues/33)).
|
48
60
|
|
49
61
|
***
|
50
62
|
|
data/lib/combine_pdf/fonts.rb
CHANGED
@@ -89,7 +89,7 @@ module CombinePDF
|
|
89
89
|
# returns a list containing the registered font names
|
90
90
|
def fonts_list
|
91
91
|
initiate_library
|
92
|
-
FONTS_LIBRARY.keys
|
92
|
+
FONTS_LIBRARY.keys
|
93
93
|
end
|
94
94
|
|
95
95
|
# gets the original font object from the fonts library (this allows you to edit the font).
|
@@ -207,12 +207,15 @@ module CombinePDF
|
|
207
207
|
end
|
208
208
|
|
209
209
|
# Register a font that already exists in a pdf object into the font library.
|
210
|
-
#
|
210
|
+
#
|
211
|
+
# The implementation is experimental, but this function attempts to deconstruct a font object in order to
|
212
|
+
# extract it's cmap and metric data, allowing it's use in the CombinePDF library.
|
213
|
+
#
|
211
214
|
def register_font_from_pdf_object font_name, font_object
|
212
215
|
# FIXME:
|
213
216
|
# - add stream deflation for the CMap file.
|
214
217
|
# - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
|
215
|
-
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
|
218
|
+
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
|
216
219
|
|
217
220
|
# first, create cmap, as it will be used to correctly create the widths directory.
|
218
221
|
|
@@ -238,7 +241,7 @@ module CombinePDF
|
|
238
241
|
if font_object[:DescendantFonts]
|
239
242
|
old_widths = font_object[:DescendantFonts]
|
240
243
|
old_widths = old_widths[:referenced_object][:indirect_without_dictionary] if old_widths[:is_reference_only]
|
241
|
-
old_widths = old_widths[0][:referenced_object]
|
244
|
+
old_widths = old_widths[0][:referenced_object]
|
242
245
|
avrg_height = 360
|
243
246
|
avrg_height = old_widths[:XHeight] if old_widths[:XHeight]
|
244
247
|
avrg_height = (avrg_height + old_widths[:CapHeight])/2 if old_widths[:CapHeight]
|
@@ -257,7 +260,7 @@ module CombinePDF
|
|
257
260
|
a = old_widths.shift
|
258
261
|
b = old_widths.shift
|
259
262
|
if b.is_a?(Array)
|
260
|
-
b.each_index {|i| metrics[ cmap_inverted[(a+i)] || (a+i) ] = {wx: b[i], boundingbox: avarage_bbox} }
|
263
|
+
b.each_index {|i| metrics[ cmap_inverted[(a+i)] || (a+i) ] = {wx: b[i], boundingbox: avarage_bbox} }
|
261
264
|
else
|
262
265
|
c = old_widths.shift
|
263
266
|
(b-a).times {|i| metrics[cmap_inverted[(a+i)] || (a+i)] = {wx: c[0], boundingbox: avarage_bbox} }
|
@@ -371,7 +374,7 @@ module CombinePDF
|
|
371
374
|
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible (albit very rare).
|
372
375
|
def self.parse_cmap(stream = "")
|
373
376
|
# FIXME:
|
374
|
-
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
|
377
|
+
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
|
375
378
|
|
376
379
|
# when 0..255
|
377
380
|
# warn "coded to char"
|
@@ -446,7 +449,7 @@ module CombinePDF
|
|
446
449
|
cmap["%c" % line[2][j].hex] = format % i #FixMe? for now limit to 8 Byte data
|
447
450
|
j += 1
|
448
451
|
i += 1
|
449
|
-
end
|
452
|
+
end
|
450
453
|
else
|
451
454
|
format = "%0#{line[0].length}x"
|
452
455
|
i = line[0].hex
|
@@ -460,15 +463,9 @@ module CombinePDF
|
|
460
463
|
end
|
461
464
|
end
|
462
465
|
end
|
463
|
-
warn "CMap is empty even after parsing!\nthese were the lines found: #{lines_found}\nfrom: #{scanner.string}" if cmap.empty?
|
466
|
+
warn "CMap is empty even after parsing!\nthese were the lines found: #{lines_found}\nfrom: #{scanner.string}" if cmap.empty?
|
464
467
|
cmap
|
465
468
|
end
|
466
469
|
|
467
470
|
end
|
468
471
|
end
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
@@ -441,6 +441,38 @@ module CombinePDF
|
|
441
441
|
self
|
442
442
|
end
|
443
443
|
|
444
|
+
# crops the page using a <b>relative</b> size.
|
445
|
+
#
|
446
|
+
# `crop` will crop the page by updating it's MediaBox property using a <b>relative</b> crop box. i.e.,
|
447
|
+
# when cropping a page with {#page_size} of [10,10,900,900] to [5,5,500,500], the resulting page size should be [15, 15, 510, 510] - allowing you to ignore a page's initial XY starting point when cropping.
|
448
|
+
#
|
449
|
+
# for an absolute cropping, simpy use the {#mediabox=} or {#cropbox=} methods, setting their value to the new {page_size}.
|
450
|
+
#
|
451
|
+
# accepts:
|
452
|
+
# new_size:: an Array with four elements: [X0, Y0, X_max, Y_max]. For example, inch4(width)x6(length): `[200, 200, 488, 632]`
|
453
|
+
def crop(new_size=nil)
|
454
|
+
# no crop box? clear any cropping.
|
455
|
+
return page_size if !new_size
|
456
|
+
# type safety
|
457
|
+
raise TypeError, "pdf.page\#crop expeceted an Array (or nil)" unless Array === new_size
|
458
|
+
|
459
|
+
# set the MediaBox to the existing page size
|
460
|
+
self[:MediaBox] = page_size
|
461
|
+
# clear the CropBox
|
462
|
+
self[:CropBox] = nil
|
463
|
+
# update X0
|
464
|
+
self[:MediaBox][0] += new_size[0]
|
465
|
+
# update Y0
|
466
|
+
self[:MediaBox][1] += new_size[1]
|
467
|
+
# update X max IF the value is smaller then the existing value
|
468
|
+
self[:MediaBox][2] = (self[:MediaBox][0] + new_size[2] - new_size[0]) if ((self[:MediaBox][0] + new_size[2] - new_size[0]) < self[:MediaBox][2])
|
469
|
+
# update Y max IF the value is smaller then the existing value
|
470
|
+
self[:MediaBox][3] = (self[:MediaBox][1] + new_size[3] - new_size[1]) if ((self[:MediaBox][1] + new_size[3] - new_size[1]) < self[:MediaBox][3])
|
471
|
+
# return self for chaining
|
472
|
+
self
|
473
|
+
end
|
474
|
+
|
475
|
+
|
444
476
|
# rotate the page 90 degrees counter clockwise
|
445
477
|
def rotate_left
|
446
478
|
self[:Rotate] = self[:Rotate].to_f + 90
|
data/lib/combine_pdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combine_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-rc4
|