File Attachment Annotation Class

Table of Contents

  1. Introduction
    1. Methods
      1. Example

        Introduction

        A file attachment annotation contains a reference to a file, which is embedded in the PDF file. It is represented by the \setasign\SetaPDF2\Core\Document\Page\Annotation\FileAttachmentAnnotation class.

        Methods

        The classes implements getter and setter methods to access the individual annotation data:

        getFileSpecification()

        Get the file specification.

        getIconName()

        Get the icon name of the annotation.

        setFileSpecification()

        Set the file specification.

        setIconName()

        Set the name of the icon that shall be used in displaying the annotation.

        Example

        PHP
        <?php
        
        use setasign\SetaPDF2\Core\Document;
        use setasign\SetaPDF2\Core\Document\Page\Annotation\FileAttachmentAnnotation;
        use setasign\SetaPDF2\Core\FileSpecification;
        use setasign\SetaPDF2\Core\PageFormats;
        use setasign\SetaPDF2\Core\Writer\HttpWriter;
        
        require_once('library/SetaPDF/Autoload.php');
        
        $writer = new HttpWriter('file-attachment-annotation.pdf', true);
        $document = new Document($writer);
        
        // let's create a page
        $pages = $document->getCatalog()->getPages();
        $page = $pages->create(PageFormats::A4);
        
        $annotations = $page->getAnnotations();
        
        // create an embedded file specification
        $fs = FileSpecification::createEmbedded(
            $document, 'files/pdfs/tektown/Logo.pdf', 'Logo.pdf'
        );
        // create the file attachment annotation
        $annotation = new FileAttachmentAnnotation(
            [50, 550, 70, 590], $fs
        );
        // set the icon name
        $annotation->setIconName(FileAttachmentAnnotation::ICON_PAPERCLIP);
        
        // set the color to blue
        $annotation->setColor([0, 0, 1]);
        
        // add the annotation to the page
        $annotations->add($annotation);
        
        $document->save()->finish();