Adding Bookmarks to a PDF

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

jps8834
User
Posts: 15
Joined: Tue Jan 27, 2009 2:38 pm

Adding Bookmarks to a PDF

Post by jps8834 »

In my program, there is a PDF created from a bunch of others. We merge the PDFs into one fine, and I have the total number of pages for each individual document, but for some reason when I try to actually add the bookmarks, it doesn't work. We want to put a bookmark on the first page of each document. I know that the code I am including doesn't quite do that, but when I open the PDF, there are NO BOOKMARKS... and I don't know why?

(This is in Delphi 5)

Here is what I have:

Code: Select all

  i, numPages, SourceStartPage : Integer;
  sKey, sDevCode, SourceFile : String;
  hr : HRESULT;
  SourcePDF : hPDF;
  Range : array of PXCP_CopyPageRange;

  PagesCount : array of Integer;

  BookmarkInfo : PXCP_BMInfo;
  DocHandle, ParentHandle : PXCp_BMHandle;
  strBookmarkTitle : WideString;

Code: Select all

  DestinationDocument := 0;
  hr := PXCp_Init(@DestinationDocument, PChar(sKey), PChar(sDevCode));
  hr := PXCp_ReadDocumentW(DestinationDocument, PWChar(WideString(DestFile)), 0);

  ZeroMemory( @(BookmarkInfo), sizeof(BookmarkInfo) );
  BookmarkInfo.cbSize := sizeof( BookmarkInfo );

  hr := PXCp_GetRootBMItem(DestinationDocument, @(ParentHandle) );

  if( IS_DS_FAILED( hr ) ) then begin
    ZeroMemory( @(BookmarkInfo), sizeof(BookmarkInfo) );
    BookmarkInfo.cbSize := sizeof( BookmarkInfo );
    BookmarkInfo.Mask := BMIM_TitleA or BMIM_Style or BMIM_Color or BMIM_Destination;
    strBookmarkTitle := 'root';
    BookmarkInfo.TitleA := PChar(strBookMarkTitle);
    BookmarkInfo.LengthOfTitle := Length(strBookMarkTitle);

    hr := PXCp_BMInsertItem(DestinationDocument, 0, PBM_ROOT, @(ParentHandle), @(BookmarkInfo));

    with BookmarkInfo do begin
      BookmarkInfo.Mask := BMIM_TitleA or BMIM_Style or BMIM_Color or BMIM_Destination;
      strBookmarkTitle := 'root';

      TitleA := PChar(strBookMarkTitle);
      LengthOfTitle := Length(strBookMarkTitle);
      style := OutlineStyle_Normal;
      Color := clBlack;

      with BookmarkInfo.Destination do begin
        DestType := Dest_Page;
        mask := 0;
        Left := 0;
        Top := 0;
        Right := 0;
        Bottom := 0;
        Zoom := 0;

        PageNumber := 0;
      end;

      PXCp_BMSetItemInfo( DestinationDocument, ParentHandle, @(BookmarkInfo) );
    end;
  end;

//  BookmarkInfo.Mask := BMIM_TitleA;
//  hr := PXCp_BMGetItemInfo( DestinationDocument, ParentHandle, @(BookmarkInfo) );

  for i := 0 to NumPDFs do begin
    ZeroMemory( @(BookmarkInfo), sizeof( BookmarkInfo ) );
    BookmarkInfo.cbSize := sizeof( BookmarkInfo );
    BookmarkInfo.Mask := BMIM_TitleA or BMIM_Style or BMIM_Color or BMIM_Destination;
    strBookmarkTitle := 'Document ' + IntToStr(i);
    BookmarkInfo.TitleA := PChar( strBookmarkTitle );
    BookmarkInfo.LengthOfTitle := Length( strBookmarkTitle ) + 1;

    ZeroMemory( @(BookmarkInfo), sizeof( BookmarkInfo ) );
    BookmarkInfo.cbSize := sizeof( BookmarkInfo );

    with BookmarkInfo.Destination do begin
      Mask := 0;
      DestType := Dest_Page;
      PageNumber := PagesCount[i];
      Left := 0;
      Right := 0;
      Top := 0;
      Bottom := 0;
      Zoom := 0;
    end;

    BookmarkInfo.Mask := BMIM_TitleA or BMIM_Style or BMIM_Color or BMIM_Destination;
    strBookmarkTitle := 'Document ' + IntToStr(i);
    BookmarkInfo.TitleA := PChar( strBookmarkTitle );
    BookmarkInfo.LengthOfTitle := Length( strBookmarkTitle ) + 1;
    BookmarkInfo.Style := 0;
    BookmarkInfo.Color := clBlack;

    PXCp_BMSetItemInfo( DestinationDocument, ParentHandle, @(BookmarkInfo) );
  end;

  PXCp_Delete( DestinationDocument );
  Result := True;
Any thoughts as to why this doesn't work?
jps8834
User
Posts: 15
Joined: Tue Jan 27, 2009 2:38 pm

Re: Adding Bookmarks to a PDF

Post by jps8834 »

So all I really want to do is to put bookmarks on certain pages and then bring them to those pages... regardless of what my code actually does, that is the intention.
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Adding Bookmarks to a PDF

Post by Lzcat - Tracker Supp »

To make changes in PDF file you must save it after modification, dont you agree?
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.