lib/hexapdf/document.rb in hexapdf-0.36.0 vs lib/hexapdf/document.rb in hexapdf-0.37.0
- old
+ new
@@ -118,10 +118,11 @@
autoload(:Fonts, 'hexapdf/document/fonts')
autoload(:Images, 'hexapdf/document/images')
autoload(:Files, 'hexapdf/document/files')
autoload(:Destinations, 'hexapdf/document/destinations')
autoload(:Layout, 'hexapdf/document/layout')
+ autoload(:Metadata, 'hexapdf/document/metadata')
# :call-seq:
# Document.open(filename, **docargs) -> doc
# Document.open(filename, **docargs) {|doc| block} -> obj
#
@@ -484,10 +485,20 @@
# See: #cache, #cached?
def clear_cache(pdf_data = nil)
pdf_data ? @cache[pdf_data].clear : @cache.clear
end
+ # Returns the Metadata object that provides a convenience interface for working with the
+ # document metadata.
+ #
+ # Note that invoking this method means that, depending on the settings, the info dictionary as
+ # well as the metadata stream will be overwritten when the document gets written. See the
+ # "Caveats" section in the Metadata documentation.
+ def metadata
+ @metadata ||= Metadata.new(self)
+ end
+
# Returns the Pages object that provides convenience methods for working with the pages of the
# PDF file.
#
# See: Pages, Type::PageTreeNode
def pages
@@ -704,15 +715,19 @@
#
# optimize::
# Optimize the file size by using object and cross-reference streams. This will raise the PDF
# version to at least 1.5.
def write(file_or_io, incremental: false, validate: true, update_fields: true, optimize: false)
- dispatch_message(:complete_objects)
-
if update_fields
trailer.update_id
- trailer.info[:ModDate] = Time.now
+ if @metadata
+ metadata.modification_date(Time.now)
+ else
+ trailer.info[:ModDate] = Time.now
+ end
end
+
+ dispatch_message(:complete_objects)
if validate
self.validate(auto_correct: true) do |msg, correctable, obj|
next if correctable
raise HexaPDF::Error, "Validation error for (#{obj.oid},#{obj.gen}): #{msg}"