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 SetaPDF_Core_Document_Page_Annotation_FileAttachment 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
        require_once('library/SetaPDF/Autoload.php');
        
        $writer = new \SetaPDF_Core_Writer_Http('file-attachment-annotation.pdf', true);
        $document = new \SetaPDF_Core_Document($writer);
        
        // let's create a page
        $pages = $document->getCatalog()->getPages();
        $page = $pages->create(\SetaPDF_Core_PageFormats::A4);
        
        $annotations = $page->getAnnotations();
        
        // create an embedded file specification
        $fs = \SetaPDF_Core_FileSpecification::createEmbedded(
            $document, 'files/pdfs/tektown/Logo.pdf', 'Logo.pdf'
        );
        // create the file attachment annotation
        $annotation = new \SetaPDF_Core_Document_Page_Annotation_FileAttachment(
            [50, 550, 70, 590], $fs
        );
        // set the icon name
        $annotation->setIconName(
            \SetaPDF_Core_Document_Page_Annotation_FileAttachment::ICON_PAPERCLIP
        );
        
        // set the color to blue
        $annotation->setColor([0, 0, 1]);
        
        // add the annotation to the page
        $annotations->add($annotation);
        
        $document->save()->finish();