From 3ecc701b4858f74d0689bc65e62fd874f6abab7c Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 18:22:16 +0000
Subject: [PATCH 01/20] EmbeddedFile PDF object definition
---
lib/prawn/embedded_files/embedded_file.rb | 42 +++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 lib/prawn/embedded_files/embedded_file.rb
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
new file mode 100644
index 000000000..3130df837
--- /dev/null
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'digest/md5'
+
+module Prawn
+ module EmbeddedFiles
+ class EmbeddedFile
+ attr_reader :chksum
+
+ def initialize(data, options = {})
+ @creation_date = options[:creation_date]
+ unless @creation_date.instance_of?(Time)
+ @creation_date = Time.now.utc
+ end
+
+ @mod_date = options[:modification_date]
+ unless @mod_date.instance_of?(Time)
+ @mod_date = Time.now.utc
+ end
+
+ @chksum = Digest::MD5.hexdigest(data)
+ @data = data.dup
+ end
+
+ def build_pdf_object(document)
+ obj = document.ref!(
+ Type: :EmbeddedFile,
+ Params: {
+ CreationDate: @creation_date,
+ ModDate: @mod_date,
+ CheckSum: PDF::Core::LiteralString.new(@chksum),
+ Size: @data.length
+ }
+ )
+
+ obj << @data
+ obj.stream.compress!
+ obj
+ end
+ end
+ end
+end
From 375f85e2aa16b2d0672634d4c4946d9006e02519 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 18:22:36 +0000
Subject: [PATCH 02/20] Filespec PDF object definition
---
lib/prawn/embedded_files/filespec.rb | 42 ++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 lib/prawn/embedded_files/filespec.rb
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
new file mode 100644
index 000000000..465c8459e
--- /dev/null
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module Prawn
+ module EmbeddedFiles
+ class Filespec
+ attr_reader :file_name, :not_hidden
+
+ def initialize(file, options = {})
+ name = options[:name] || file.chksum
+
+ @file_name = PDF::Core::LiteralString.new(name)
+
+ if options[:description]
+ desc_str = options[:description].to_s
+ @description = PDF::Core::LiteralString.new(desc_str)
+ end
+
+ if options[:hidden].nil? || options[:hidden] != true
+ @not_hidden = true
+ end
+
+ @file = file
+ end
+
+ def hidden
+ !@not_hidden
+ end
+
+ def build_pdf_object(document)
+ obj = document.ref!(
+ Type: :Filespec,
+ F: @file_name,
+ EF: { F: @file },
+ UF: @file_name
+ )
+
+ obj[:Desc] = @description if @description
+ obj
+ end
+ end
+ end
+end
From 83a0642c86e41d3c3d1765fa5b0006532b3486d2 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 18:24:15 +0000
Subject: [PATCH 03/20] Document file attachment method definition
---
lib/prawn/embedded_files.rb | 43 +++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 lib/prawn/embedded_files.rb
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
new file mode 100644
index 000000000..5d086f605
--- /dev/null
+++ b/lib/prawn/embedded_files.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module Prawn
+ module EmbeddedFiles
+ # include PDF::Core::EmbeddedFiles
+ # Link to PR (https://github.com/prawnpdf/pdf-core/pull/47)
+
+ def file(src, options = {})
+ path = Pathname.new(src)
+
+ if path.directory?
+ raise ArgumentError, 'Data source can\'t be a directory'
+ elsif path.file?
+ data = path.read
+ options[:name] ||= src
+ else
+ data = src
+ end
+
+ @file_registry ||= {}
+
+ file = EmbeddedFile.new(data, options)
+ file_obj = @file_registry[file.chksum]
+
+ if file_obj.nil?
+ file_obj = file.build_pdf_object(self)
+ @file_registry[file.chksum] = file_obj
+ end
+
+ filespec = Filespec.new(file_obj, options)
+ filespec_obj = filespec.build_pdf_object(self)
+
+ unless filespec.hidden
+ # Wait for pdf-core PR
+
+ # attach_file(filespec.file_name, filespec_obj)
+ end
+ end
+ end
+end
+
+require_relative 'embedded_files/embedded_file'
+require_relative 'embedded_files/filespec'
From 9461d9839403dab4dc70f0fce696e9662f040a4c Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 18:26:29 +0000
Subject: [PATCH 04/20] EmbeddedFiles module included in Prawn::Document class
and lib
---
lib/prawn.rb | 1 +
lib/prawn/document.rb | 1 +
2 files changed, 2 insertions(+)
diff --git a/lib/prawn.rb b/lib/prawn.rb
index 05f4aeb78..06b441a3d 100644
--- a/lib/prawn.rb
+++ b/lib/prawn.rb
@@ -61,6 +61,7 @@ def verify_options(accepted, actual)
require_relative 'prawn/images/image'
require_relative 'prawn/images/jpg'
require_relative 'prawn/images/png'
+require_relative 'prawn/embedded_files'
require_relative 'prawn/stamp'
require_relative 'prawn/soft_mask'
require_relative 'prawn/security'
diff --git a/lib/prawn/document.rb b/lib/prawn/document.rb
index 439667d5a..03cd472b7 100644
--- a/lib/prawn/document.rb
+++ b/lib/prawn/document.rb
@@ -55,6 +55,7 @@ class Document
include Prawn::Text
include Prawn::Graphics
include Prawn::Images
+ include Prawn::EmbeddedFiles
include Prawn::Stamp
include Prawn::SoftMask
include Prawn::TransformationStack
From 0fb2b56c81a8a16ce8d9fb48967a47071eb00709 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 22:10:17 +0000
Subject: [PATCH 05/20] Creation and modification dates from file information
---
lib/prawn/embedded_files.rb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index 5d086f605..7e055ccc8 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -13,6 +13,8 @@ def file(src, options = {})
elsif path.file?
data = path.read
options[:name] ||= src
+ options[:creation_date] ||= path.birthtime
+ options[:modification_date] ||= path.mtime
else
data = src
end
From 334c19a993e3bd0bb10d392751d9d4839a176f4f Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Wed, 21 Jul 2021 22:27:15 +0000
Subject: [PATCH 06/20] :hidden option simplification
---
lib/prawn/embedded_files.rb | 2 +-
lib/prawn/embedded_files/filespec.rb | 11 ++++-------
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index 7e055ccc8..f82af36a6 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -32,7 +32,7 @@ def file(src, options = {})
filespec = Filespec.new(file_obj, options)
filespec_obj = filespec.build_pdf_object(self)
- unless filespec.hidden
+ unless filespec.hidden?
# Wait for pdf-core PR
# attach_file(filespec.file_name, filespec_obj)
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index 465c8459e..4311ae467 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -3,7 +3,7 @@
module Prawn
module EmbeddedFiles
class Filespec
- attr_reader :file_name, :not_hidden
+ attr_reader :file_name
def initialize(file, options = {})
name = options[:name] || file.chksum
@@ -15,15 +15,12 @@ def initialize(file, options = {})
@description = PDF::Core::LiteralString.new(desc_str)
end
- if options[:hidden].nil? || options[:hidden] != true
- @not_hidden = true
- end
-
+ @hidden = options[:hidden] == true
@file = file
end
- def hidden
- !@not_hidden
+ def hidden?
+ @hidden
end
def build_pdf_object(document)
From 5680677ffbd7cc188f55f872b9974eb20f3e5ddd Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 11:59:37 +0000
Subject: [PATCH 07/20] :hidden option could be a truthy value
---
lib/prawn/embedded_files/filespec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index 4311ae467..b1932f7bd 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -15,7 +15,7 @@ def initialize(file, options = {})
@description = PDF::Core::LiteralString.new(desc_str)
end
- @hidden = options[:hidden] == true
+ @hidden = options[:hidden]
@file = file
end
From 6796763a3576d8cd643d8fd4d39070162e7b8bb4 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 12:04:26 +0000
Subject: [PATCH 08/20] Look for the Time class in the object's superclasses as
well
---
lib/prawn/embedded_files/embedded_file.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index 3130df837..4a00a8c01 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -9,12 +9,12 @@ class EmbeddedFile
def initialize(data, options = {})
@creation_date = options[:creation_date]
- unless @creation_date.instance_of?(Time)
+ unless @creation_date.kind_of?(Time)
@creation_date = Time.now.utc
end
@mod_date = options[:modification_date]
- unless @mod_date.instance_of?(Time)
+ unless @mod_date.kind_of?(Time)
@mod_date = Time.now.utc
end
From ca636340c8a24dba9d0c0975c7d41a5235841c91 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 12:05:54 +0000
Subject: [PATCH 09/20] Using MD5 digest instead of the hex-encoded one
---
lib/prawn/embedded_files/embedded_file.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index 4a00a8c01..c9aef49ce 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -18,7 +18,7 @@ def initialize(data, options = {})
@mod_date = Time.now.utc
end
- @chksum = Digest::MD5.hexdigest(data)
+ @chksum = Digest::MD5.digest(data)
@data = data.dup
end
From b96039be0af5dc09327131309e90f332ac8851e0 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 12:06:50 +0000
Subject: [PATCH 10/20] Avoiding wasteful duplication
---
lib/prawn/embedded_files/embedded_file.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index c9aef49ce..d2ba58889 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -19,7 +19,7 @@ def initialize(data, options = {})
end
@chksum = Digest::MD5.digest(data)
- @data = data.dup
+ @data = data
end
def build_pdf_object(document)
From f41ed2cf09568f09781ea39b833511cf664bafd8 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 22:54:13 +0000
Subject: [PATCH 11/20] Checksum attribute renamed
---
lib/prawn/embedded_files.rb | 4 ++--
lib/prawn/embedded_files/embedded_file.rb | 6 +++---
lib/prawn/embedded_files/filespec.rb | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index f82af36a6..0ff128799 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -22,11 +22,11 @@ def file(src, options = {})
@file_registry ||= {}
file = EmbeddedFile.new(data, options)
- file_obj = @file_registry[file.chksum]
+ file_obj = @file_registry[file.checksum]
if file_obj.nil?
file_obj = file.build_pdf_object(self)
- @file_registry[file.chksum] = file_obj
+ @file_registry[file.checksum] = file_obj
end
filespec = Filespec.new(file_obj, options)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index d2ba58889..adf9c7f66 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -5,7 +5,7 @@
module Prawn
module EmbeddedFiles
class EmbeddedFile
- attr_reader :chksum
+ attr_reader :checksum
def initialize(data, options = {})
@creation_date = options[:creation_date]
@@ -18,7 +18,7 @@ def initialize(data, options = {})
@mod_date = Time.now.utc
end
- @chksum = Digest::MD5.digest(data)
+ @checksum = Digest::MD5.digest(data)
@data = data
end
@@ -28,7 +28,7 @@ def build_pdf_object(document)
Params: {
CreationDate: @creation_date,
ModDate: @mod_date,
- CheckSum: PDF::Core::LiteralString.new(@chksum),
+ CheckSum: PDF::Core::LiteralString.new(@checksum),
Size: @data.length
}
)
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index b1932f7bd..33619531b 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -6,7 +6,7 @@ class Filespec
attr_reader :file_name
def initialize(file, options = {})
- name = options[:name] || file.chksum
+ name = options[:name] || file.checksum
@file_name = PDF::Core::LiteralString.new(name)
From f0c04536a9b56c054ffd67e797047f6a835439f6 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 23:02:12 +0000
Subject: [PATCH 12/20] Filespec description key set wrongly fixed
---
lib/prawn/embedded_files/filespec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index 33619531b..18fa786d3 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -31,7 +31,7 @@ def build_pdf_object(document)
UF: @file_name
)
- obj[:Desc] = @description if @description
+ obj.data[:Desc] = @description if @description
obj
end
end
From a6343c1c02d77cb1517986b4ec4990a047bc95a7 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 23:24:32 +0000
Subject: [PATCH 13/20] Avoiding instance variables outside method
---
lib/prawn/embedded_files/embedded_file.rb | 20 ++++++++++++--------
lib/prawn/embedded_files/filespec.rb | 12 ++++++++----
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index adf9c7f66..bd4d7b1fb 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -13,9 +13,9 @@ def initialize(data, options = {})
@creation_date = Time.now.utc
end
- @mod_date = options[:modification_date]
- unless @mod_date.kind_of?(Time)
- @mod_date = Time.now.utc
+ @modification_date = options[:modification_date]
+ unless @modification_date.kind_of?(Time)
+ @modification_date = Time.now.utc
end
@checksum = Digest::MD5.digest(data)
@@ -26,17 +26,21 @@ def build_pdf_object(document)
obj = document.ref!(
Type: :EmbeddedFile,
Params: {
- CreationDate: @creation_date,
- ModDate: @mod_date,
- CheckSum: PDF::Core::LiteralString.new(@checksum),
- Size: @data.length
+ CreationDate: creation_date,
+ ModDate: modification_date,
+ CheckSum: PDF::Core::LiteralString.new(checksum),
+ Size: data.length
}
)
- obj << @data
+ obj << data
obj.stream.compress!
obj
end
+
+ private
+
+ attr_reader :data, :creation_date, :modification_date
end
end
end
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index 18fa786d3..c79e89bd0 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -26,14 +26,18 @@ def hidden?
def build_pdf_object(document)
obj = document.ref!(
Type: :Filespec,
- F: @file_name,
- EF: { F: @file },
- UF: @file_name
+ F: file_name,
+ EF: { F: file },
+ UF: file_name
)
- obj.data[:Desc] = @description if @description
+ obj.data[:Desc] = description if description
obj
end
+
+ private
+
+ attr_reader :file, :description
end
end
end
From fe6486098311018a0ded5e19130b2b0fd358e6dc Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 23:46:54 +0000
Subject: [PATCH 14/20] Honoring document compression option
---
lib/prawn/embedded_files/embedded_file.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index bd4d7b1fb..0ac6c0ebb 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -34,7 +34,7 @@ def build_pdf_object(document)
)
obj << data
- obj.stream.compress!
+ obj.stream.compress! if document.compression_enabled?
obj
end
From 8d4e0471c13edb08a84f0e7bc6d439ef09545f6d Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Thu, 22 Jul 2021 23:57:56 +0000
Subject: [PATCH 15/20] Avoiding changes of parameters
---
lib/prawn/embedded_files.rb | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index 0ff128799..699be8a97 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -7,21 +7,22 @@ module EmbeddedFiles
def file(src, options = {})
path = Pathname.new(src)
+ mut_opts = options.dup
if path.directory?
raise ArgumentError, 'Data source can\'t be a directory'
elsif path.file?
data = path.read
- options[:name] ||= src
- options[:creation_date] ||= path.birthtime
- options[:modification_date] ||= path.mtime
+ mut_opts[:name] ||= src
+ mut_opts[:creation_date] ||= path.birthtime
+ mut_opts[:modification_date] ||= path.mtime
else
data = src
end
@file_registry ||= {}
- file = EmbeddedFile.new(data, options)
+ file = EmbeddedFile.new(data, mut_opts)
file_obj = @file_registry[file.checksum]
if file_obj.nil?
@@ -29,7 +30,7 @@ def file(src, options = {})
@file_registry[file.checksum] = file_obj
end
- filespec = Filespec.new(file_obj, options)
+ filespec = Filespec.new(file_obj, mut_opts)
filespec_obj = filespec.build_pdf_object(self)
unless filespec.hidden?
From 484d7011d77dbedf3bf98dede05c11b91c204176 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Fri, 23 Jul 2021 10:59:53 +0000
Subject: [PATCH 16/20] Using hex-encoded digest as default name
---
lib/prawn/embedded_files/embedded_file.rb | 2 +-
lib/prawn/embedded_files/filespec.rb | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index 0ac6c0ebb..867f2e6c0 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'digest/md5'
+require 'digest'
module Prawn
module EmbeddedFiles
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index c79e89bd0..41646cbaa 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -1,12 +1,15 @@
# frozen_string_literal: true
+require 'digest'
+
module Prawn
module EmbeddedFiles
class Filespec
attr_reader :file_name
def initialize(file, options = {})
- name = options[:name] || file.checksum
+ hexdigest = Digest.hexencode(file.data[:Params][:CheckSum])
+ name = options[:name] || hexdigest
@file_name = PDF::Core::LiteralString.new(name)
From 097ee850de27e86bbba51788f348fedc64e1ed18 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Fri, 23 Jul 2021 11:04:19 +0000
Subject: [PATCH 17/20] Setting 'UF' entry in the 'EF' dictionary as well
---
lib/prawn/embedded_files/filespec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/prawn/embedded_files/filespec.rb b/lib/prawn/embedded_files/filespec.rb
index 41646cbaa..07b51337b 100644
--- a/lib/prawn/embedded_files/filespec.rb
+++ b/lib/prawn/embedded_files/filespec.rb
@@ -30,7 +30,7 @@ def build_pdf_object(document)
obj = document.ref!(
Type: :Filespec,
F: file_name,
- EF: { F: file },
+ EF: { F: file, UF: file },
UF: file_name
)
From 8f09896d68c97a4de08d064fc8fafe167f7e46e6 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Tue, 27 Jul 2021 15:24:28 +0000
Subject: [PATCH 18/20] 'file' method documentation
---
lib/prawn/embedded_files.rb | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index 699be8a97..a9a9c29ad 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -5,6 +5,30 @@ module EmbeddedFiles
# include PDF::Core::EmbeddedFiles
# Link to PR (https://github.com/prawnpdf/pdf-core/pull/47)
+ # Add the file's data from a source to the document. Any kind of data with
+ # a string representation can be embedded.
+ #
+ # Arguments:
+ # src:: path to file, string or an object that responds to #to_str
+ # and #length.
+ #
+ # Options:
+ # :name:: explicit default filename override.
+ # :creation_date:: date when the file was created.
+ # :modification_date:: date when the file was last modified.
+ # :description:: file description.
+ # :hidden:: if true, prevents the file from appearing in the
+ # catalog. (default false)
+ #
+ # Prawn::Document.generate("file1.pdf") do
+ # dice = "#{Prawn::DATADIR}/images/dice.png"
+ # file dice, description: 'Example of an embedded image file'
+ # end
+ #
+ # This method returns an instance of PDF::Core::NameTree::Value
+ # corresponding to the file in the embedded files catalog entry node. If
+ # hidden, then nil is returned.
+ #
def file(src, options = {})
path = Pathname.new(src)
mut_opts = options.dup
From 5d3011e9521dbb93c497ceda7b5a4a325b2bbc41 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Tue, 27 Jul 2021 15:25:04 +0000
Subject: [PATCH 19/20] File registration refactor
---
lib/prawn/embedded_files.rb | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb
index a9a9c29ad..01af76343 100644
--- a/lib/prawn/embedded_files.rb
+++ b/lib/prawn/embedded_files.rb
@@ -44,14 +44,12 @@ def file(src, options = {})
data = src
end
- @file_registry ||= {}
-
file = EmbeddedFile.new(data, mut_opts)
- file_obj = @file_registry[file.checksum]
+ file_obj = file_registry[file.checksum]
if file_obj.nil?
file_obj = file.build_pdf_object(self)
- @file_registry[file.checksum] = file_obj
+ file_registry[file.checksum] = file_obj
end
filespec = Filespec.new(file_obj, mut_opts)
@@ -63,6 +61,12 @@ def file(src, options = {})
# attach_file(filespec.file_name, filespec_obj)
end
end
+
+ private
+
+ def file_registry
+ @file_registry ||= {}
+ end
end
end
From 3714d596652a7a32fb75c3243b3472282c397d35 Mon Sep 17 00:00:00 2001
From: David Lilue <2525462+dvdalilue@users.noreply.github.com>
Date: Fri, 13 Aug 2021 18:50:09 +0000
Subject: [PATCH 20/20] 'is_a?' is preferable to 'kind_of?'
---
lib/prawn/embedded_files/embedded_file.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/prawn/embedded_files/embedded_file.rb b/lib/prawn/embedded_files/embedded_file.rb
index 867f2e6c0..524092071 100644
--- a/lib/prawn/embedded_files/embedded_file.rb
+++ b/lib/prawn/embedded_files/embedded_file.rb
@@ -9,12 +9,12 @@ class EmbeddedFile
def initialize(data, options = {})
@creation_date = options[:creation_date]
- unless @creation_date.kind_of?(Time)
+ unless @creation_date.is_a?(Time)
@creation_date = Time.now.utc
end
@modification_date = options[:modification_date]
- unless @modification_date.kind_of?(Time)
+ unless @modification_date.is_a?(Time)
@modification_date = Time.now.utc
end