Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /AFRelationship and /Subtype to embedded files #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/prawn/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def prepare_options(name, opts)
creation_date: opts[:created_at] || Time.now.utc,
modification_date: opts[:modified_at] || Time.now.utc,
description: opts[:description],
hidden: !!opts[:hidden]
hidden: !!opts[:hidden],
relationship: opts[:relationship],
mime_type: opts[:mime_type]
}
end

Expand Down
7 changes: 5 additions & 2 deletions lib/prawn/attachment/embedded_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Prawn
module Attachment
# EmbeddedFile represents a file to be embedded in the PDF.
class EmbeddedFile
attr_reader :data, :creation_date, :modification_date, :checksum
attr_reader :data, :creation_date, :modification_date, :subtype, :checksum

def initialize(data, options = {})
@data = data
Expand All @@ -15,6 +15,8 @@ def initialize(data, options = {})
@modification_date = options[:modification_date]
@modification_date = Time.now.utc unless @modification_date.is_a?(Time)

@subtype = (options[:mime_type] || "application/octet-stream").to_sym

@checksum = Digest::MD5.digest(data)
end

Expand All @@ -35,7 +37,8 @@ def reference_params
ModDate: modification_date,
CheckSum: PDF::Core::LiteralString.new(checksum),
Size: data.length
}
},
Subtype: subtype
}
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/prawn/attachment/filespec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def initialize(file, options = {})
end

@hidden = options[:hidden]

if options[:relationship]
@relationship = options[:relationship]
end
@file = file
end

Expand All @@ -36,12 +40,13 @@ def build_pdf_object(document)
)

obj.data[:Desc] = description if description
obj.data[:AFRelationship] = relationship if relationship
obj
end

private

attr_reader :file, :description
attr_reader :file, :description, :relationship
end
end
end