combine_pdf 0.0.12 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20e1c50aa5948f3a2ba3ad9c170ba08bc3e8ec38
|
4
|
+
data.tar.gz: 75ed75edadc4fcdee63ab579419f83f8685a8c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b70a1624d699441aab808da4ee0461796d643607622a42c2ecd58342bebd8ee8f1edcc633962e93b36dba82c0ba89400f29b06f7e115d3e21eaf0803130f032
|
7
|
+
data.tar.gz: 8e5d4f16d65cd2306149dc69012aae66d5295f54d18760a335cf32fd68c3d9bd2563689bee87e44724c260653d232ddb2db93ef7e91d4c27265a48da96e7b616
|
data/lib/combine_pdf.rb
CHANGED
@@ -32,11 +32,9 @@ load "combine_pdf/combine_pdf_pdf.rb"
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
-
# This is a pure ruby library to merge PDF files.
|
35
|
+
# This is a pure ruby library to combine/merge, stmap/overlay and number PDF files.
|
36
36
|
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# PDF objects can be used to combine or to inject data.
|
37
|
+
# You can also use this library for writing basic text content into new or existing PDF files (For authoring new PDF files look at the Prawn ruby library).
|
40
38
|
#
|
41
39
|
# here is the most basic application for the library, a one-liner that combines the PDF files and saves them:
|
42
40
|
# (CombinePDF.new("file1.pdf") << CombinePDF.new("file2.pdf") << CombinePDF.new("file3.pdf")).save("combined.pdf")
|
@@ -59,7 +57,7 @@ load "combine_pdf/combine_pdf_pdf.rb"
|
|
59
57
|
# pdf.save "combined.pdf"
|
60
58
|
# as demonstrated above, these can be chained for into a one-liner.
|
61
59
|
#
|
62
|
-
# you can also only
|
60
|
+
# you can also choose to add only specific pages.
|
63
61
|
#
|
64
62
|
# in this example, only even pages will be added:
|
65
63
|
# pdf = CombinePDF.new
|
@@ -77,15 +75,14 @@ load "combine_pdf/combine_pdf_pdf.rb"
|
|
77
75
|
# in this example, a company logo will be stamped over each page:
|
78
76
|
# company_logo = CombinePDF.new("company_logo.pdf").pages[0]
|
79
77
|
# pdf = CombinePDF.new "content_file.pdf"
|
80
|
-
# pdf.pages.each {|page| page << company_logo}
|
78
|
+
# pdf.pages.each {|page| page << company_logo}
|
81
79
|
# pdf.save "content_with_logo.pdf"
|
82
80
|
# Notice the << operator is on a page and not a PDF object. The << operator acts differently on PDF objects and on Pages.
|
83
81
|
#
|
84
|
-
# The << operator defaults to secure injection by renaming references to avoid conflics.
|
85
|
-
# pdf.pages(nil, false).each {|page| page << stamp_page}
|
86
|
-
#
|
82
|
+
# The << operator defaults to secure injection by renaming references to avoid conflics.
|
87
83
|
#
|
88
|
-
#
|
84
|
+
# Less recommended, but available - for overlaying pages using compressed data that might not be editable (due to limited filter support), you can use:
|
85
|
+
# pdf.pages(nil, false).each {|page| page << stamp_page}
|
89
86
|
#
|
90
87
|
# == Page Numbering
|
91
88
|
# adding page numbers to a PDF object or file is as simple as can be:
|
@@ -406,14 +406,20 @@ module CombinePDF
|
|
406
406
|
out = []
|
407
407
|
scanner = StringScanner.new text
|
408
408
|
until scanner.eos? do
|
409
|
-
if scanner.scan /[#{rtl_characters}]/
|
410
|
-
out.unshift scanner.matched
|
411
|
-
end
|
412
|
-
if scanner.scan /[^#{rtl_characters}]+/
|
409
|
+
if scanner.scan /[#{rtl_characters} ]/
|
413
410
|
out.unshift scanner.matched
|
411
|
+
elsif scanner.scan /[^#{rtl_characters}]+/
|
412
|
+
if out.empty? && scanner.matched.match(/[\s]$/) && !scanner.eos?
|
413
|
+
warn "MOVING SPACE: #{scanner.matched}"
|
414
|
+
white_space_to_move = scanner.matched.match(/[\s]+$/).to_s
|
415
|
+
out.unshift scanner.matched[0..-1-white_space_to_move.length]
|
416
|
+
out.unshift white_space_to_move
|
417
|
+
else
|
418
|
+
out.unshift scanner.matched
|
419
|
+
end
|
414
420
|
end
|
415
421
|
end
|
416
|
-
out.join
|
422
|
+
out.join.strip
|
417
423
|
end
|
418
424
|
end
|
419
425
|
|
@@ -15,7 +15,7 @@ module CombinePDF
|
|
15
15
|
#
|
16
16
|
# this Hash lists the private Hash keys that the CombinePDF library uses to
|
17
17
|
# differentiate between complex PDF objects.
|
18
|
-
PRIVATE_HASH_KEYS = [:indirect_reference_id, :indirect_generation_number, :raw_stream_content, :is_reference_only, :referenced_object, :indirect_without_dictionary
|
18
|
+
PRIVATE_HASH_KEYS = [:indirect_reference_id, :indirect_generation_number, :raw_stream_content, :is_reference_only, :referenced_object, :indirect_without_dictionary]
|
19
19
|
#@private
|
20
20
|
#:nodoc: all
|
21
21
|
|
@@ -130,6 +130,8 @@ module CombinePDF
|
|
130
130
|
names_dictionary.each do |old_key, new_key|
|
131
131
|
stream[:raw_stream_content].gsub! _object_to_pdf(old_key), _object_to_pdf(new_key) ##### PRAY(!) that the parsed datawill be correctly reproduced!
|
132
132
|
end
|
133
|
+
# patch back to PDF defaults, for OCRed PDF files.
|
134
|
+
stream[:raw_stream_content] = "q\nq\nq\nDeviceRGB CS\nDeviceRGB cs\n0 0 0 rg\n0 0 0 RG\n0 Tr\n%s\nQ\nQ\nQ\n" % stream[:raw_stream_content]
|
133
135
|
end
|
134
136
|
|
135
137
|
new_page
|
@@ -48,9 +48,6 @@ module CombinePDF
|
|
48
48
|
# The << operator defaults to secure injection by renaming references to avoid conflics. For overlaying pages using compressed data that might not be editable (due to limited filter support), you can use:
|
49
49
|
# pdf.pages(nil, false).each {|page| page << stamp_page}
|
50
50
|
#
|
51
|
-
#
|
52
|
-
# Notice that page objects are Hash class objects and the << operator was added to the Page instances without altering the class.
|
53
|
-
#
|
54
51
|
# == Page Numbering
|
55
52
|
# adding page numbers to a PDF object or file is as simple as can be:
|
56
53
|
# pdf = CombinePDF.new "file_to_number.pdf"
|
@@ -281,8 +278,11 @@ module CombinePDF
|
|
281
278
|
return self #return self object for injection chaining (pdf << page << page << page)
|
282
279
|
end
|
283
280
|
|
284
|
-
# LATIN ONLY - NO UNICODE SUPPORT YET
|
285
281
|
# add page numbers to the PDF
|
282
|
+
#
|
283
|
+
# For unicode text, a unicode font(s) must first be registered. the registered font(s) must supply the
|
284
|
+
# subset of characters used in the text. UNICODE IS AN ISSUE WITH THE PDF FORMAT - USE CAUSION.
|
285
|
+
#
|
286
286
|
# options:: a Hash of options setting the behavior and format of the page numbers:
|
287
287
|
# - :number_format a string representing the format for page number. defaults to ' - %s - ' (allows for letter numbering as well, such as "a", "b"...).
|
288
288
|
# - :number_location an Array containing the location for the page numbers, can be :top, :buttom, :top_left, :top_right, :bottom_left, :bottom_right. defaults to [:top, :buttom].
|