Class: Pdfrb::Document::Portfolio
- Inherits:
-
Object
- Object
- Pdfrb::Document::Portfolio
- Defined in:
- lib/pdfrb/document/portfolio.rb
Overview
PDF Portfolio facade. A portfolio is a PDF with a /Collection dictionary on the Catalog that provides a collection view of embedded files (ISO 32000-2 ยง12.3.5).
Inspired by mn2pdf's PDFPortfolio (which uses PDFBox). Provides field schema, default view configuration, and per-item metadata.
Defined Under Namespace
Constant Summary collapse
- DEFAULT_FIELDS =
[ { name: "Name", type: :text }.freeze, { name: "Description", type: :text, subtype: :Description }.freeze, { name: "Size", type: :number }.freeze, { name: "Modified", type: :date, subtype: :CreationDate }.freeze, ].freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#schema_fields ⇒ Object
readonly
Returns the value of attribute schema_fields.
Instance Method Summary collapse
-
#add_field(name, type: :text, subtype: nil, order: nil) ⇒ Object
Add a schema field.
-
#add_item(name, file_bytes, mime_type: nil, description: nil, fields: {}) ⇒ Object
Add an item (embedded file) to the portfolio.
-
#commit! ⇒ Object
Commit the portfolio configuration to the document.
-
#initialize(document) ⇒ Portfolio
constructor
A new instance of Portfolio.
Constructor Details
#initialize(document) ⇒ Portfolio
Returns a new instance of Portfolio.
34 35 36 37 38 |
# File 'lib/pdfrb/document/portfolio.rb', line 34 def initialize(document) @document = document @items = [] @schema_fields = DEFAULT_FIELDS.map { |f| Field.new(**f) } end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
32 33 34 |
# File 'lib/pdfrb/document/portfolio.rb', line 32 def document @document end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
32 33 34 |
# File 'lib/pdfrb/document/portfolio.rb', line 32 def items @items end |
#schema_fields ⇒ Object (readonly)
Returns the value of attribute schema_fields.
32 33 34 |
# File 'lib/pdfrb/document/portfolio.rb', line 32 def schema_fields @schema_fields end |
Instance Method Details
#add_field(name, type: :text, subtype: nil, order: nil) ⇒ Object
Add a schema field. Order matters for display.
41 42 43 44 45 46 47 48 |
# File 'lib/pdfrb/document/portfolio.rb', line 41 def add_field(name, type: :text, subtype: nil, order: nil) @schema_fields << Field.new( name: name, type: type, subtype: subtype, order: order || @schema_fields.length ) end |
#add_item(name, file_bytes, mime_type: nil, description: nil, fields: {}) ⇒ Object
Add an item (embedded file) to the portfolio.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pdfrb/document/portfolio.rb', line 51 def add_item(name, file_bytes, mime_type: nil, description: nil, fields: {}) @items << Item.new( name: name, file_bytes: file_bytes, mime_type: mime_type, description: description, fields: fields ) end |
#commit! ⇒ Object
Commit the portfolio configuration to the document. Sets /Collection on the Catalog, creates /Filespec for each item, and embeds the file data via /EF.
65 66 67 68 |
# File 'lib/pdfrb/document/portfolio.rb', line 65 def commit! catalog = document.catalog catalog.value[:Collection] = collection_dict end |