Exemplo n.º 1
0
function AnnotationLowLevelAPI($doc)
{
    $page = $doc->GetPageIterator()->Current();
    $annots = $page->GetAnnots();
    if (!$annots) {
        // If there are no annotations, create a new annotation
        // array for the page.
        $annots = $doc->CreateIndirectArray();
        $page->GetSDFObj()->Put("Annots", $annots);
    }
    // Create a Text annotation
    $annot = $doc->CreateIndirectDict();
    $annot->PutName("Subtype", "Text");
    $annot->PutBool("Open", true);
    $annot->PutString("Contents", "The quick brown fox ate the lazy mouse.");
    $annot->PutRect("Rect", 266, 116, 430, 204);
    // Insert the annotation in the page annotation array
    $annots->PushBack($annot);
    // Create a Link annotation
    $link1 = $doc->CreateIndirectDict();
    $link1->PutName("Subtype", "Link");
    $dest = Destination::CreateFit($doc->GetPage(2));
    $link1->Put("Dest", $dest->GetSDFObj());
    $link1->PutRect("Rect", 85, 705, 503, 661);
    $annots->PushBack($link1);
    // Create another Link annotation
    $link2 = $doc->CreateIndirectDict();
    $link2->PutName("Subtype", "Link");
    $dest2 = Destination::CreateFit($doc->GetPage(3));
    $link2->Put("Dest", $dest2->GetSDFObj());
    $link2->PutRect("Rect", 85, 638, 503, 594);
    $annots->PushBack($link2);
    // Note that PDFNet API can be used to modify existing annotations.
    // In the following example we will modify the second link annotation
    // (link2) so that it points to the 10th page. We also use a different
    // destination page fit type.
    // $link2 = $annots->GetAt($annots->Size()-1);
    $link2->Put("Dest", Destination::CreateXYZ($doc->GetPage(10), 100, 792 - 70, 10)->GetSDFObj());
    // Create a third link annotation with a hyperlink action (all other
    // annotation types can be created in a similar way)
    $link3 = $doc->CreateIndirectDict();
    $link3->PutName("Subtype", "Link");
    $link3->PutRect("Rect", 85, 570, 503, 524);
    // Create a URI action
    $action = $link3->PutDict("A");
    $action->PutName("S", "URI");
    $action->PutString("URI", "http://www.pdftron.com");
    $annots->PushBack($link3);
}