combine_pdf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/combine_pdf/combine_pdf_pdf.rb +51 -26
- 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: 1415b642f2d84f101f6f444d16191faa35d3a6b9
|
4
|
+
data.tar.gz: aa872079b6576afd266bcb2b628772e80e33b9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78ada1b24bc160cc492b272dd31a1115a76dd217baebbac78fc259a077720427c837c053c5fe54cdfab6f84629142a45275629a714f693a6e8416bf47cb3bfa7
|
7
|
+
data.tar.gz: 03ced7106be2f831f5dc51df810d810f1f8b1828f8d6364800eb4d248764d30a6e67281b5d34d40fdbe5581673e9da1bed7a494f094e4a7ef4d6550c6e2984f2
|
@@ -235,7 +235,7 @@ module CombinePDF
|
|
235
235
|
page_list
|
236
236
|
end
|
237
237
|
|
238
|
-
#
|
238
|
+
# add the pages (or file) to the PDF (combine/merge) and return the new pages array.
|
239
239
|
# for example:
|
240
240
|
#
|
241
241
|
# pdf = CombinePDF.new "first_file.pdf"
|
@@ -243,39 +243,64 @@ module CombinePDF
|
|
243
243
|
# pdf << CombinePDF.new "second_file.pdf"
|
244
244
|
#
|
245
245
|
# pdf.save "both_files_merged.pdf"
|
246
|
-
#
|
247
|
-
def << (
|
246
|
+
# data:: is PDF page (Hash), and Array of PDF pages or a parsed PDF object to be added.
|
247
|
+
def << (data)
|
248
248
|
#########
|
249
249
|
## how should we add data to PDF?
|
250
250
|
## and how to handles imported pages?
|
251
|
-
|
252
|
-
|
253
|
-
@version = [@version, obj.version].max
|
251
|
+
if data.is_a?(PDF)
|
252
|
+
@version = [@version, data.version].max
|
254
253
|
|
255
|
-
|
254
|
+
@need_to_rebuild_resources = true
|
256
255
|
|
257
|
-
@objects.push(*
|
256
|
+
@objects.push(*data.objects)
|
258
257
|
# rebuild_catalog
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
258
|
+
return rebuild_catalog[:Pages][:referenced_object][:Kids]
|
259
|
+
end
|
260
|
+
insert -1, data
|
261
|
+
end
|
262
|
+
|
263
|
+
# add the pages (or file) to the BEGINNING of the PDF (combine/merge) and return the new pages array.
|
264
|
+
# for example:
|
265
|
+
#
|
266
|
+
# pdf = CombinePDF.new "second_file.pdf"
|
267
|
+
#
|
268
|
+
# pdf >> CombinePDF.new "first_file.pdf"
|
269
|
+
#
|
270
|
+
# pdf.save "both_files_merged.pdf"
|
271
|
+
# data:: is PDF page (Hash), and Array of PDF pages or a parsed PDF object to be added.
|
272
|
+
def >> (data)
|
273
|
+
insert 0, data
|
274
|
+
end
|
275
|
+
|
276
|
+
# add PDF pages (or PDF files) into a specific location.
|
277
|
+
#
|
278
|
+
# returns the new pages Array
|
279
|
+
#
|
280
|
+
# location:: the location for the added page(s). Could be any number. negative numbers represent a count backwards (-1 being the end of the page array and 0 being the begining). if the location is beyond bounds, the pages will be added to the end of the PDF object (or at the begining, if the out of bounds was a negative number).
|
281
|
+
# data:: a PDF page, a PDF file (CombinePDF.new "filname.pdf") or an array of pages (CombinePDF.new("filname.pdf").pages[0..3]).
|
282
|
+
def insert(location, data)
|
283
|
+
pages_to_add = nil
|
284
|
+
if data.is_a? PDF
|
285
|
+
pages_to_add = data.pages
|
286
|
+
elsif data.is_a?(Array) && (data.select {|o| !(o.is_a?(Hash) && o[:Type] == :Page) } ).empty?
|
287
|
+
pages_to_add = data
|
288
|
+
elsif data.is_a?(Hash) && data[:Type] == :Page
|
289
|
+
pages_to_add = [data]
|
274
290
|
else
|
275
|
-
warn "Shouldn't add objects to the file
|
276
|
-
retrun false # return false, which will also stop any chaining.
|
291
|
+
warn "Shouldn't add objects to the file unless they are PDF objects or PDF pages (an Array or a single PDF page)."
|
292
|
+
retrun false # return false, which will also stop any chaining.
|
293
|
+
end
|
294
|
+
catalog = rebuild_catalog
|
295
|
+
pages_array = catalog[:Pages][:referenced_object][:Kids]
|
296
|
+
page_count = pages_array.length
|
297
|
+
if location < 0 && (page_count + location < 0 )
|
298
|
+
location = 0
|
299
|
+
elsif location > 0 && (location > page_count)
|
300
|
+
location = page_count
|
277
301
|
end
|
278
|
-
|
302
|
+
pages_array.insert location, pages_to_add
|
303
|
+
pages_array
|
279
304
|
end
|
280
305
|
|
281
306
|
# add page numbers to the PDF
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combine_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-rc4
|