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);
}
Exemplo n.º 2
0
$key = "blue1";
$blue_action = Action::CreateGoto($key, strlen($key), Destination::CreateFit($doc->GetPage(19)));
$blue->SetAction($blue_action);
// We can now add children Bookmarks
$sub_red1 = $red->AddChild("Red - Page 1");
$sub_red1->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(1))));
$sub_red2 = $red->AddChild("Red - Page 2");
$sub_red2->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(2))));
$sub_red3 = $red->AddChild("Red - Page 3");
$sub_red3->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(3))));
$sub_red4 = $sub_red3->AddChild("Red - Page 4");
$sub_red4->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(4))));
$sub_red5 = $sub_red3->AddChild("Red - Page 5");
$sub_red5->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(5))));
$sub_red6 = $sub_red3->AddChild("Red - Page 6");
$sub_red6->SetAction(Action::CreateGoto(Destination::CreateFit($doc->GetPage(6))));
// Example of how to find and delete a bookmark by title text.
$foo = $doc->GetFirstBookmark()->Find("foo");
if ($foo->IsValid()) {
    $foo->Delete();
} else {
    assert(false);
}
$bar = $doc->GetFirstBookmark()->Find("bar");
if ($bar->IsValid()) {
    $bar->Delete();
} else {
    assert(false);
}
// Adding color to Bookmarks. Color and other formatting can help readers
// get around more easily in large PDF documents.