lib/hexapdf/document.rb in hexapdf-0.47.0 vs lib/hexapdf/document.rb in hexapdf-1.0.0
- old
+ new
@@ -722,14 +722,16 @@
dest.trailer.delete(:Encrypt)
dest
end
# :call-seq:
- # doc.write(filename, incremental: false, validate: true, update_fields: true, optimize: false)
- # doc.write(io, incremental: false, validate: true, update_fields: true, optimize: false)
+ # doc.write(filename, incremental: false, validate: true, update_fields: true, optimize: false) -> [start_xref, section]
+ # doc.write(io, incremental: false, validate: true, update_fields: true, optimize: false) -> [start_xref, section]
#
- # Writes the document to the given file (in case +io+ is a String) or IO stream.
+ # Writes the document to the given file (in case +io+ is a String) or IO stream. Returns the
+ # file position of the start of the last cross-reference section and the last XRefSection object
+ # written.
#
# Before the document is written, it is validated using #validate and an error is raised if the
# document is not valid. However, this step can be skipped if needed.
#
# Options:
@@ -780,9 +782,18 @@
if file_or_io.kind_of?(String)
File.open(file_or_io, 'w+') {|file| Writer.write(self, file, incremental: incremental) }
else
Writer.write(self, file_or_io, incremental: incremental)
end
+ end
+
+ # Writes the document to a string and returns the string.
+ #
+ # See #write for further information and details on the available arguments.
+ def write_to_string(**args)
+ io = StringIO.new(''.b)
+ write(io)
+ io.string
end
def inspect #:nodoc:
"<#{self.class.name}:#{object_id}>"
end