combine_pdf 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/combine_pdf/api.rb +6 -1
- data/lib/combine_pdf/page_methods.rb +15 -9
- data/lib/combine_pdf/parser.rb +1 -1
- data/lib/combine_pdf/pdf_protected.rb +1 -1
- data/lib/combine_pdf/pdf_public.rb +12 -6
- data/lib/combine_pdf/version.rb +2 -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: 84c4c10854fe1876f80ef97367f22ac2ea60e2b1
|
4
|
+
data.tar.gz: 6ebc1e28df2124ceb2f845532601e48f962b908e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4779c64b3e923500c2e0aaab1e655763b9b055e5c85b44d00d304fc5e39f851ac075b8530453b55e3565c3ee540e584c518744de7e516b0dbceaa3109b2a30ae
|
7
|
+
data.tar.gz: 567e5a818742da6e0b76e5eb647cde9b8b98ed184b557e0b1c6718f289559097b145f34647c4a5cac12521f42027c97184aa973af2bb18a0b3742423d73444c3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
Change log v.0.2.3
|
6
|
+
|
7
|
+
**update**: a better general error message for CombinePDF.new
|
8
|
+
|
9
|
+
**fix**: the `make_secure` now correctly sets the secure copy flag, as expected. For performance reasons it is better to use page.copy(true) for renaming conflicting resource identifiers, but if multiple secure copies are needed for some reason, using `make_secure` will now make sure each copy is secured independently.
|
10
|
+
|
11
|
+
**fix**: the secure copy now worked as expected (it had issue with referenced resource dictionaries that was resolved by following the references).
|
12
|
+
|
13
|
+
**fix**: fixed an object numbering issue introduced by duplicating pages as part of the Adobe Reader bug workaround. The issue was thought to have been fixed before but some PDF structures were not proprly addressed.
|
14
|
+
|
15
|
+
***
|
16
|
+
|
5
17
|
Change log v.0.2.2
|
6
18
|
|
7
19
|
**fix**: fixed the default value for the :location attribute of PDF#stamp_pages(String, options). Now, instead of the default stamp being written at [:top, :bottom], it's default location will be set to [:center].
|
data/lib/combine_pdf/api.rb
CHANGED
@@ -25,7 +25,12 @@ module CombinePDF
|
|
25
25
|
def new(string = false)
|
26
26
|
return PDF.new unless string
|
27
27
|
raise TypeError, "couldn't create PDF object, expecting type String" unless string.is_a?(String) || string.is_a?(Pathname)
|
28
|
-
|
28
|
+
begin
|
29
|
+
(File.file? string rescue false) ? load(string) : parse(string)
|
30
|
+
rescue => e
|
31
|
+
raise 'General PDF error - Use CombinePDF.load or CombinePDF.parse for a non-general error message (the requested file was not found OR the string received is not a valid PDF stream OR the file was found but not valid).'
|
32
|
+
end
|
33
|
+
|
29
34
|
end
|
30
35
|
|
31
36
|
# Create a PDF object from a raw PDF data (parsing the data).
|
@@ -542,9 +542,10 @@ module CombinePDF
|
|
542
542
|
self
|
543
543
|
end
|
544
544
|
|
545
|
+
# creates a copy of the page. if the :secure flag is set to true, the resource indentifiers (fonts etc') will be renamed in order to secure their uniqueness.
|
546
|
+
def copy(secure = false)
|
545
547
|
# since only the Content streams are modified (Resource hashes are created anew),
|
546
548
|
# it should be safe (and a lot faster) to create a deep copy only for the content hashes and streams.
|
547
|
-
def copy(secure = false)
|
548
549
|
delete :Parent
|
549
550
|
prep_content_array
|
550
551
|
page_copy = self.clone
|
@@ -555,15 +556,15 @@ module CombinePDF
|
|
555
556
|
obj
|
556
557
|
end
|
557
558
|
if page_copy[:Resources]
|
558
|
-
page_copy[:Resources] = page_copy[:Resources].dup
|
559
|
-
page_copy[:Resources][:referenced_object] = page_copy[:Resources][:referenced_object].dup if page_copy[:Resources][:referenced_object]
|
560
|
-
page_res = page_copy.resources
|
559
|
+
page_res = page_copy[:Resources] = page_copy[:Resources].dup
|
560
|
+
page_res = page_copy[:Resources][:referenced_object] = page_copy[:Resources][:referenced_object].dup if page_copy[:Resources][:referenced_object]
|
561
561
|
page_res.each do |k, v|
|
562
|
-
page_res[k] = v.dup if v.is_a?(Array) || v.is_a?(Hash)
|
563
|
-
v[:referenced_object] = v[:referenced_object].dup if v.is_a?(Hash) && v[:referenced_object]
|
562
|
+
v = page_res[k] = v.dup if v.is_a?(Array) || v.is_a?(Hash)
|
563
|
+
v = v[:referenced_object] = v[:referenced_object].dup if v.is_a?(Hash) && v[:referenced_object]
|
564
|
+
v = v[:referenced_object] = v[:referenced_object].dup if v.is_a?(Hash) && v[:referenced_object]
|
564
565
|
end
|
565
566
|
end
|
566
|
-
return page_copy.instance_exec(secure) { |s| secure_for_copy if s ; init_contents; self }
|
567
|
+
return page_copy.instance_exec(secure || @secure_injection) { |s| secure_for_copy if s ; init_contents; self }
|
567
568
|
end
|
568
569
|
|
569
570
|
###################################
|
@@ -749,8 +750,13 @@ module CombinePDF
|
|
749
750
|
names_dictionary = {}
|
750
751
|
|
751
752
|
# travel every dictionary to pick up names (keys), change them and add them to the dictionary
|
752
|
-
self
|
753
|
+
res = self.resources
|
754
|
+
res.each do |k,v|
|
753
755
|
if v.is_a?(Hash)
|
756
|
+
# if k == :XObject
|
757
|
+
# self[:Resources][k] = v.dup
|
758
|
+
# next
|
759
|
+
# end
|
754
760
|
new_dictionary = {}
|
755
761
|
new_name = "Combine" + SecureRandom.hex(7) + "PDF"
|
756
762
|
i = 1
|
@@ -760,7 +766,7 @@ module CombinePDF
|
|
760
766
|
new_dictionary[new_key] = value
|
761
767
|
i += 1
|
762
768
|
end
|
763
|
-
|
769
|
+
res[k] = new_dictionary
|
764
770
|
end
|
765
771
|
end
|
766
772
|
|
data/lib/combine_pdf/parser.rb
CHANGED
@@ -349,7 +349,7 @@ module CombinePDF
|
|
349
349
|
|
350
350
|
|
351
351
|
# resets cataloging and pages
|
352
|
-
def catalog_pages(catalogs = nil, secure_injection =
|
352
|
+
def catalog_pages(catalogs = nil, secure_injection = false, inheritance_hash = {})
|
353
353
|
unless catalogs
|
354
354
|
|
355
355
|
if root_object[:Root]
|
@@ -35,7 +35,7 @@ module CombinePDF
|
|
35
35
|
# first if statement is actually a workaround for a bug in Acrobat Reader, regarding duplicate pages.
|
36
36
|
if object[:is_reference_only] && object[:referenced_object] && object[:referenced_object].is_a?(Hash) && object[:referenced_object][:Type] == :Page
|
37
37
|
if @objects.find_index object[:referenced_object]
|
38
|
-
@objects << object[:referenced_object].dup
|
38
|
+
@objects << (object[:referenced_object] = object[:referenced_object].dup)
|
39
39
|
else
|
40
40
|
@objects << object[:referenced_object]
|
41
41
|
end
|
@@ -303,6 +303,7 @@ module CombinePDF
|
|
303
303
|
warn "Shouldn't add objects to the file unless they are PDF objects or PDF pages (an Array or a single PDF page)."
|
304
304
|
return false # return false, which will also stop any chaining.
|
305
305
|
end
|
306
|
+
# pages_to_add.map! {|page| page.copy }
|
306
307
|
catalog = rebuild_catalog
|
307
308
|
pages_array = catalog[:Pages][:referenced_object][:Kids]
|
308
309
|
page_count = pages_array.length
|
@@ -363,6 +364,11 @@ module CombinePDF
|
|
363
364
|
just_center = [:center]
|
364
365
|
small_font_size = opt[:font_size] || 12
|
365
366
|
|
367
|
+
# some common computations can be done only once.
|
368
|
+
from_height = opt[:margin_from_height]
|
369
|
+
from_side = opt[:margin_from_side]
|
370
|
+
left_position = from_side
|
371
|
+
|
366
372
|
(opt[:page_range] ? pages[opt[:page_range]] : pages).each do |page|
|
367
373
|
# Get page dimensions
|
368
374
|
mediabox = page[:CropBox] || page[:MediaBox] || [0, 0, 595.3, 841.9]
|
@@ -384,20 +390,20 @@ module CombinePDF
|
|
384
390
|
add_opt = { font_size: small_font_size }.merge(opt)
|
385
391
|
# text = opt[:number_format] % page_number
|
386
392
|
# compute locations for text boxes
|
387
|
-
text_dimantions =
|
393
|
+
text_dimantions = Fonts.dimensions_of( text, opt[:font], small_font_size )
|
388
394
|
box_width = text_dimantions[0] * 1.2
|
389
395
|
box_height = text_dimantions[1] * 2
|
390
|
-
add_opt[:width] ||= box_width
|
391
|
-
add_opt[:height] ||= box_height
|
392
|
-
from_height = add_opt[:margin_from_height]
|
393
|
-
from_side = add_opt[:margin_from_side]
|
394
396
|
page_width = mediabox[2]
|
395
397
|
page_height = mediabox[3]
|
398
|
+
|
399
|
+
add_opt[:width] ||= box_width
|
400
|
+
add_opt[:height] ||= box_height
|
401
|
+
|
396
402
|
center_position = (page_width - box_width)/2
|
397
|
-
left_position = from_side
|
398
403
|
right_position = page_width - from_side - box_width
|
399
404
|
top_position = page_height - from_height
|
400
405
|
bottom_position = from_height + box_height
|
406
|
+
|
401
407
|
if opt[:location].include? :top
|
402
408
|
page.textbox text, {x: center_position, y: top_position }.merge(add_opt)
|
403
409
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-rc4
|