def attach_file(path, register: true, name: nil, filter: :FlateDecode)

            if path.is_a? FileSpec
                filespec = path
                name ||= ''
            else
                if path.respond_to?(:read)
                    data = path.read.force_encoding('binary')
                    name ||= ''
                else
                    data = File.binread(File.expand_path(path))
                    name ||= File.basename(path)
                end

                fstream = EmbeddedFileStream.new
                fstream.data = data

                fstream.Filter = filter
                filespec = FileSpec.new(:F => fstream)
            end

            fspec = FileSpec.new.setType(:Filespec).setF(name.dup).setEF(filespec)

            self.register(
                Names::EMBEDDED_FILES,
                name.dup,
                fspec
            ) if register

            fspec
        end
def attach_file(path, register: true, name: nil, filter: :FlateDecode)

            if path.is_a? FileSpec
                filespec = path
                name ||= ''
            else
                if path.respond_to?(:read)
                    data = path.read.force_encoding('binary')
                    name ||= ''
                else
                    data = File.binread(File.expand_path(path))
                    name ||= File.basename(path)
                end

                fstream = EmbeddedFileStream.new
                fstream.data = data

                fstream.Filter = filter
                filespec = FileSpec.new(:F => fstream)
            end

            fspec = FileSpec.new.setType(:Filespec).setF(name.dup).setEF(filespec)

            self.register(
                Names::EMBEDDED_FILES,
                name.dup,
                fspec
            ) if register

            fspec
        end
Attachs an embedded file to the PDF.
 _path_:: The path to the file to attach.
 _register_:: Whether the file shall be registered in the name directory.
 _name_:: The embedded file name of the attachment.
 _filter_:: The stream filter used to store the file contents.