-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c94f468
commit 0cae866
Showing
1 changed file
with
11 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require 'stringio' | ||
require 'securerandom' | ||
require 'digest' | ||
|
||
module PDF | ||
module Core | ||
|
@@ -163,9 +163,9 @@ def render(output = StringIO.new) | |
finalize_all_page_contents | ||
|
||
render_header(output) | ||
render_body(output) | ||
body_hash = render_body(output) | ||
render_xref(output) | ||
render_trailer(output) | ||
render_trailer(output, body_hash) | ||
if output.instance_of?(StringIO) | ||
str = output.string | ||
str.force_encoding(::Encoding::ASCII_8BIT) | ||
|
@@ -198,7 +198,13 @@ def render_header(output) | |
# Write out the PDF Body, as per spec 3.4.2 | ||
# | ||
def render_body(output) | ||
body_start = output.tell | ||
state.render_body(output) | ||
body_end = output.tell | ||
output.seek body_start | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Backbone81
Author
|
||
body_hash = Digest::MD5.digest output.read(body_end - body_start) | ||
output.seek body_end | ||
body_hash | ||
end | ||
|
||
# Write out the PDF Cross Reference Table, as per spec 3.4.3 | ||
|
@@ -216,8 +222,8 @@ def render_xref(output) | |
|
||
# Write out the PDF Trailer, as per spec 3.4.4 | ||
# | ||
def render_trailer(output) | ||
trailer_id = PDF::Core::ByteString.new(SecureRandom.random_bytes(16)) | ||
def render_trailer(output, body_hash) | ||
trailer_id = PDF::Core::ByteString.new(body_hash) | ||
trailer_hash = { | ||
Size: state.store.size + 1, | ||
Root: state.store.root, | ||
|
Not all IOs are seekable. Sor example,
STDOUT
is not.I'd rather split hashing out as well. One method renders body, another hashes it.