SetBookmark

The SetBookmark method creates a bookmark on the specified page. Users will then be able to browse through the document by clicking on the bookmarks tree.

 

Syntax

ActiveX:

System.Boolean SetBookmark(System.Int32 Page, System.String Text, System.Int32 Level)

 

Parameters

Page

Page number specifying the location of the bookmark.

Text

Bookmark text.

Level

Increase or decrease level of the bookmark in the bookmark tree.

 

Return Value

It returns True if successful and False upon failure.

 

Remarks

The bookmark level will be the same than previous bookmark if zero is used as Level parameter.  Positive values will increase the depth and negative values will decrease the depth in the bookmark tree.

 

 

Member of CDIntfEx.Document.

 

Example

To create the following bookmark structure:

    

 

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF18074B8441306C5739F7DC52654D393BA9CECBA2ADE79E3762A66FFC354008A5F4A5811BE3204A0A439F5BA"

 

    ' Declare a new cdintfex document if it does not exist in the form.

    Dim pdfDoc As New CDIntfEx.Document

 

    ' The SetLicenseKey method should be called after creating an object of type 

    ' CDIntfEx.Document to activate the advanced methods that require the object 

    ' activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Open the document

    pdfDoc.Open("c:\temp\test.pdf")

 

    ' SetBookmark

    n = 0 'do not change the level

    For page=1 To pdfDoc.PageCount

        pdfDoc.SetBookmark(page,("BookMark " & page, n)

        pdfDoc.SetBookmark page,("BookMark A" & page, 1)  'increase the level in 1

        pdfDoc.SetBookmark page,("BookMark B" & page, 1)  'increase the level in 1

        n = -2 ' decrease 2 levels to return to initial level

    Next

    ' Save the document

    pdfDoc.Save("c:\temp\Bookmarked.pdf")

 

    ' Destroy pdfDoc object

    pdfDoc = Nothing 

End Sub

public void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF18074B8441306C5739F7DC52654D393BA9CECBA2ADE79E3762A66FFC354008A5F4A5811BE3204A0A439F5BA";

 

    // Declare a new cdintfex document if it does not exist in the form.

    CDIntfEx.Document pdfDoc = new CDIntfEx.Document();

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Open the document

    pdfDoc.Open(@"c:\temp\test.pdf");

 

    // SetBookmark

    var n = 0; // do not change the level

    for (var page = 1; page <= pdfDoc.PageCount; page++)

    {

        pdfDoc.SetBookmark(page, "BookMark " + page.ToString(), n);

        pdfDoc.SetBookmark(page, "BookMark A" + page.ToString(), 1);  // increase the level in 1

        pdfDoc.SetBookmark(page, "BookMark B" + page.ToString(), 1);  // increase the level in 1

        n = -2; // decrease 2 levels to return to initial level

    }

 

    // Save the document

    pdfDoc.Save(@"c:\temp\Bookmarked.pdf");

 

    // Destroy pdfDoc object

    pdfDoc = null;

}

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF18074B8441306C5739F7DC52654D393BA9CECBA2ADE79E3762A66FFC354008A5F4A5811BE3204A0A439F5BA"

 

#Declare a new cdintfex document if it does not exist in the form.

$pdfDoc = New-Object -ComObject CDIntfEx.Document.6.5

 

#The SetLicenseKey method should be called after creating an object of type 

#CDIntfEx.Document to activate the advanced methods that require the object 

#activation code to work properly

[System.__ComObject].InvokeMember('SetLicenseKey' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($strLicenseTo, $strActivationCode))

 

#Open the document

[System.__ComObject].InvokeMember('Open' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\test.pdf") 

 

#SetBookmark

$pages = [System.__ComObject].InvokeMember('PageCount' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, $null)

$n = 0 #do not change the level

for ($page = 1 ; $page -le $pages ; $page++)

{

    [System.__ComObject].InvokeMember('SetBookmark' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,@($page, ("BookMark " + $page), $n))

    [System.__ComObject].InvokeMember('SetBookmark' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,@($page, ("BookMark A" + $page), 1))  #increase the level in 1

    [System.__ComObject].InvokeMember('SetBookmark' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,@($page, ("BookMark B" + $page), 1))  #increase the level in 1

    $n = -2 #decrease 2 levels to return to initial level

}

 

#Save the document

[System.__ComObject].InvokeMember('Save' ,[System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\Bookmarked.pdf") 

 

#Destroy pdfDoc object

$pdfDoc = $null

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Converter Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF18074B8441306C5739F7DC52654D393BA9CECBA2ADE79E3762A66FFC354008A5F4A5811BE3204A0A439F5BA"

 

' Declare a new Document object

Dim pdfDoc

Set pdfDoc = CreateObject("CDIntfEx.Document.6.5")

 

' The SetLicenseKey method should be called after creating an object of type 

' CDIntfEx.Document to activate the advanced methods that require the object 

' activation code to work properly

pdfDoc.SetLicenseKey strLicenseTo, strActivationCode

 

' Open the document

pdfDoc.Open "C:\temp\TESTING.pdf"

 

' SetBookmark

n = 0 'do not change the level

For page=1 To pdfDoc.PageCount

    pdfDoc.SetBookmark page, "BookMark " & page, n

    pdfDoc.SetBookmark page, "BookMark A" & page, 1  'increase the level in 1

    pdfDoc.SetBookmark page, "BookMark B" & page, 1  'increase the level in 1

    n = -2 ' decrease 2 levels to return to initial level

Next

 

' Save the document

pdfDoc.Save "c:\temp\Bookmarked.pdf"

 

' Destroy pdfDoc object

Set pdfDoc = Nothing