{
    "mode": "perldoc",
    "parameter": "PDF::API2::Annotation",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/PDF%3A%3AAPI2%3A%3AAnnotation/json",
    "generated": "2026-06-13T12:09:26Z",
    "synopsis": "my $pdf = PDF::API2->new();\nmy $font = $pdf->font('Helvetica');\nmy $page1 = $pdf->page();\nmy $page2 = $pdf->page();\nmy $content = $page1->text();\nmy $message = 'Go to Page 2';\nmy $size = 18;\n$content->distance(1 * 72, 9 * 72);\n$content->font($font, $size);\n$content->text($message);\nmy $annotation = $page1->annotation();\nmy $width = $content->textwidth($message);\n$annotation->rect(1 * 72, 9 * 72, 1 * 72 + $width, 9 * 72 + $size);\n$annotation->link($page2);\n$pdf->save('sample.pdf');",
    "sections": {
        "NAME": {
            "content": "PDF::API2::Annotation - Add annotations to a PDF\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $pdf = PDF::API2->new();\nmy $font = $pdf->font('Helvetica');\nmy $page1 = $pdf->page();\nmy $page2 = $pdf->page();\n\nmy $content = $page1->text();\nmy $message = 'Go to Page 2';\nmy $size = 18;\n$content->distance(1 * 72, 9 * 72);\n$content->font($font, $size);\n$content->text($message);\n\nmy $annotation = $page1->annotation();\nmy $width = $content->textwidth($message);\n$annotation->rect(1 * 72, 9 * 72, 1 * 72 + $width, 9 * 72 + $size);\n$annotation->link($page2);\n\n$pdf->save('sample.pdf');\n",
            "subsections": []
        },
        "METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "Annotation Types",
                    "content": "link\n$annotation = $annotation->link($destination, $location, @args);\n\nLink the annotation to another page in this PDF. $location and @args are optional and set which\npart of the page should be displayed, as defined in \"destination\" in\nPDF::API2::NamedDestination.\n\n$destination can be either a PDF::API2::Page object or the name of a named destination defined\nelsewhere.\n\nurl\n$annotation = $annotation->uri($uri);\n\nLaunch $uri -- typically a web page -- when the annotation is selected.\n\nfile\n$annotation = $annotation->launch($file);\n\nOpen $file when the annotation is selected.\n\npdf\n$annotation = $annotation->pdf($file, $pagenumber, $location, @args);\n\nOpen the PDF file located at $file to the specified page number. $location and @args are\noptional and set which part of the page should be displayed, as defined in \"destination\" in\nPDF::API2::NamedDestination.\n\ntext\n$annotation = $annotation->text($text);\n\nDefine the annotation as a text note with the specified content.\n\nmovie\n$annotation = $annotation->movie($filename, $contenttype);\n\nEmbed and link to the movie located at $filename with the specified MIME type.\n"
                },
                {
                    "name": "Common Annotation Attributes",
                    "content": "rect\n$annotation = $annotation->rect($llx, $lly, $urx, $ury);\n\nDefine the rectangle around the annotation.\n\nborder\n$annotation = $annotation->border($hradius, $vradius, $width);\n\nDefine the border style. Defaults to 0, 0, 0 (no border).\n\ncontent\n$annotation = $annotation->content(@lines);\n\nDefine the text content of the annotation, if applicable.\n\nopen\n$annotation = $annotation->open($boolean);\n\nSet the annotation to initially be either open or closed. Only relevant for text annotations.\n"
                }
            ]
        }
    },
    "summary": "PDF::API2::Annotation - Add annotations to a PDF",
    "flags": [],
    "examples": [],
    "see_also": []
}