Changing the default “start” or open page in PDF

Q: I have an existing PDF that when I open displays page 2 as the start page, pressing page up in adobe reader jumps to page 1.

  1. Can I read which page is the “start page” from a PDF with PDFNET?

  2. Is it possible to change the “start page” of this PDF to page 1 with PDFNET?


A:

The start page is the first page of the document unless the document contains an open action which specifies an action to run on startup such as going to another page.

The start page can be determined using the following code snippet:

int pageIndex=1;

Action action = doc.GetOpenAction();

if(action.IsValid() && action.GetType()==Action::e_GoTo)

{

Destination dest= action.GetDest();

if(dest.IsValid())

{

pageIndex= dest.GetPage().GetIndex();

}

}

To change the start page back to page 1 all that needs to be done is remove the open action. This can be done using the following code snippet:

Obj obj=doc.GetRoot();

if(obj){

obj->Erase(“OpenAction”);

}