Skip to contents

Creates a new /EmbeddedFile entry in doc's name tree, with the given filename. The returned handle is a pdfium_attachment that you can pass to pdf_attachment_set_data() to populate the file bytes, and pdf_attachment_set_dict_value() to populate dictionary metadata ("Subtype", "Desc", etc.).

Usage

pdf_attachment_new(doc, name)

Arguments

doc

A pdfium_doc from pdf_doc_open() or pdf_doc_new(). Must be readwrite.

name

Character scalar — the attachment's filename. UTF-8 accepted.

Value

A pdfium_attachment handle. The attachment is empty — call pdf_attachment_set_data() to populate its contents.

Details

Wraps FPDFDoc_AddAttachment. The new attachment is appended to the end of the document's existing attachment list, and its $index field reflects the resulting 1-based index. PDFium will refuse the creation (returning NULL, which we surface as an R error) if:

  • name is empty;

  • name is the name of an existing embedded file in doc;

  • the document's name tree is at its depth limit.

See also

pdf_attachments() for the read side, pdf_attachment_delete() to remove an attachment.