combine_pdf 0.2.31 → 0.2.32

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: 63b0c324e1bf003b0c0fc963eb2071b6c4672c18
4
- data.tar.gz: 34c200edda06074773888c098b9d4f9a6479d752
3
+ metadata.gz: 965be3f2286760e04ed715a9514a1205b27aaf3e
4
+ data.tar.gz: ee3098114904a30410990bd6bd0b715aae32f81d
5
5
  SHA512:
6
- metadata.gz: ebf1cd2a7c1077f71d6f41037f0ad341c06e6bbb305bfa030833956feb0bb80576e2eaa5fd7324000ff95834f8c125cafc40a782ac97c16c7e3c7e7c02166794
7
- data.tar.gz: a4cc257441939fbc0dd59dffe2d3faf11ade63b89fa2637bee8b54df7ea9e31a2ec5612d366ec9208856d750deac8fe10f1ddcaab6f9bf21996e6aa52c775e90
6
+ metadata.gz: c55779f6471f54dfd815b61dc77f62d92774f7d5dd29877af2806c7c6de5ef9eb224f8ec6b97f1f535d020227fc4026ce058098e634f974bf631ea244a622af8
7
+ data.tar.gz: 9c352999dc4fa5c694e6a14f1a6ab9b02b9615af55c8991915d89283ddfad416ff0c8b5f6efe4b19df165718b37b01a138aeac21f0d693dc491426af0e4f59cf
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+
16
+ .DS_Store
@@ -2,6 +2,14 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.2.32 (un-released)
6
+
7
+ **Update**: Better errors when encryption related exceptions occur. Credit to Paul Shumeika ( @pshumeika ).
8
+
9
+ **Fix**: Fixed an issue where empty pages with NULL contents value would cause CombinePDF to raise an exception when rendering. Credit to @holtmaat and Jason DeLeon (@progmem) (both in submitted different PRs regarding the issue).
10
+
11
+ ***
12
+
5
13
  Change log v.0.2.31
6
14
 
7
15
  **Broke**: Broke the fix for issue #65 so that Radio buttons data might be lost... working on a fix.
data/README.md CHANGED
@@ -103,7 +103,7 @@ pdf.save "file_with_numbering.pdf"
103
103
 
104
104
  Numbering can be done with many different options, with different formating, with or without a box object, and even with opacity values - see documentation.
105
105
 
106
- ## Loading and Rendering PDF data
106
+ ## Loading and Parsing PDF data
107
107
 
108
108
  Loading PDF data can be done from file system or directly from the memory.
109
109
 
@@ -120,14 +120,28 @@ pdf_data = prawn_pdf_document.render # Import PDF data from Prawn
120
120
  pdf = CombinePDF.parse(pdf_data)
121
121
  ```
122
122
 
123
- Similarly, you can output a string of PDF data using `.to_pdf`. For example, to let a user download the PDF from a [Rails](http://rubyonrails.org) or [Plezi](https://github.com/boazsegev/plezi) app:
123
+ Using `parse` is also effective when loading data from a remote location, circumventing the need for unnecessary temporary files. For example:
124
+
125
+ ```ruby
126
+ require 'combine_pdf'
127
+ require 'net/http'
128
+
129
+ url = "https://example.com/my.pdf"
130
+ pdf = CombinePDF.parse Net::HTTP.get_response(URI.parse(url)).body
131
+ ```
132
+
133
+ ## Rendering PDF data
134
+
135
+ Similarly, to loading and parsing, rendering can also be performed either to the memory or to a file.
136
+
137
+ You can output a string of PDF data using `.to_pdf`. For example, to let a user download the PDF from either a [Rails application](http://rubyonrails.org) or a [Plezi application](http://www.plezi.io):
124
138
 
125
139
  ```ruby
126
140
  # in a controller action
127
141
  send_data combined_file.to_pdf, filename: "combined.pdf", type: "application/pdf"
128
142
  ```
129
143
 
130
- Or in [Sinatra](http://www.sinatrarb.com):
144
+ In [Sinatra](http://www.sinatrarb.com):
131
145
 
132
146
  ```ruby
133
147
  # in your path's block
@@ -136,6 +150,7 @@ body combined_file.to_pdf
136
150
  headers 'content-type' => "application/pdf"
137
151
  ```
138
152
 
153
+
139
154
  If you prefer to save the PDF data to a file, you can always use the `save` method as we did in our earlier examples.
140
155
 
141
156
  Some PDF files contain optional content sections which cannot always be merged reliably. By default, an exception is
@@ -19,6 +19,7 @@ load 'combine_pdf/filter.rb'
19
19
  load 'combine_pdf/parser.rb'
20
20
  load 'combine_pdf/pdf_public.rb'
21
21
  load 'combine_pdf/pdf_protected.rb'
22
+ load 'combine_pdf/exceptions.rb'
22
23
 
23
24
  # load "combine_pdf/operations.rb"
24
25
 
@@ -25,7 +25,7 @@ module CombinePDF
25
25
  def initialize(objects = [], root_dictionary = {})
26
26
  @objects = objects
27
27
  @encryption_dictionary = actual_object(root_dictionary[:Encrypt])
28
- raise 'Cannot decrypt an encrypted file without an encryption dictionary!' unless @encryption_dictionary
28
+ raise EncryptionError, 'Cannot decrypt an encrypted file without an encryption dictionary!' unless @encryption_dictionary
29
29
  @root_dictionary = actual_object(root_dictionary)
30
30
  @padding_key = [0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
31
31
  0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
@@ -181,7 +181,7 @@ module CombinePDF
181
181
  def raise_encrypted_error(object = nil)
182
182
  object ||= @encryption_dictionary.to_s.split(',').join("\n")
183
183
  warn "Data raising exception:\n #{object.to_s.split(',').join("\n")}"
184
- raise 'File is encrypted - not supported.'
184
+ raise EncryptionError, 'File is encrypted - not supported.'
185
185
  end
186
186
 
187
187
  def change_references_to_actual_values(hash_with_references = {})
@@ -0,0 +1,4 @@
1
+ module CombinePDF
2
+ class EncryptionError < StandardError
3
+ end
4
+ end
@@ -77,13 +77,14 @@ module CombinePDF
77
77
 
78
78
  raise 'Unknown PDF parsing error - maleformed PDF file?' unless (@parsed.select { |i| !i.is_a?(Hash) }).empty?
79
79
 
80
- if @root_object == {}
80
+ if @root_object == {}.freeze
81
81
  xref_streams = @parsed.select { |obj| obj.is_a?(Hash) && obj[:Type] == :XRef }
82
82
  xref_streams.each do |xref_dictionary|
83
83
  @root_object.merge! xref_dictionary
84
84
  end
85
85
  end
86
- raise 'root is unknown - cannot determine if file is Encrypted' if @root_object == {}
86
+
87
+ raise 'root is unknown - cannot determine if file is Encrypted' if @root_object == {}.freeze
87
88
 
88
89
  if @root_object[:Encrypt]
89
90
  # change_references_to_actual_values @root_object
@@ -80,6 +80,8 @@ module CombinePDF
80
80
  ('[' + (object.collect { |item| object_to_pdf(item) }).join(' ') + ']').force_encoding(Encoding::ASCII_8BIT)
81
81
  end
82
82
 
83
+ EMPTY_PAGE_CONTENT_STREAM = {is_reference_only: true, referenced_object: { indirect_reference_id: 0, raw_stream_content: '' }}
84
+
83
85
  def format_hash_to_pdf(object)
84
86
  # if the object is only a reference:
85
87
  # special conditions apply, and there is only the setting of the reference (if needed) and output
@@ -107,7 +109,7 @@ module CombinePDF
107
109
  end
108
110
  end
109
111
  # remove extra page references.
110
- object[:Contents].delete(is_reference_only: true, referenced_object: { indirect_reference_id: 0, raw_stream_content: '' }) if object[:Type] == :Page
112
+ object[:Contents].delete(EMPTY_PAGE_CONTENT_STREAM) if object[:Type] == :Page && object[:Contents].is_a?(Array)
111
113
  # correct stream length, if the object is a stream.
112
114
  object[:Length] = object[:raw_stream_content].bytesize if object[:raw_stream_content]
113
115
 
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = '0.2.31'.freeze
2
+ VERSION = '0.2.32'.freeze
3
3
  end
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.31
4
+ version: 0.2.32
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-08-22 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4
@@ -72,6 +72,7 @@ files:
72
72
  - lib/combine_pdf/api.rb
73
73
  - lib/combine_pdf/basic_writer.rb
74
74
  - lib/combine_pdf/decrypt.rb
75
+ - lib/combine_pdf/exceptions.rb
75
76
  - lib/combine_pdf/filter.rb
76
77
  - lib/combine_pdf/fonts.rb
77
78
  - lib/combine_pdf/page_methods.rb
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  version: '0'
104
105
  requirements: []
105
106
  rubyforge_project:
106
- rubygems_version: 2.5.1
107
+ rubygems_version: 2.5.2
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Combine, stamp and watermark PDF files in pure Ruby.