Print Page | Close Window

Create bookmark tree using Delphi

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2199
Printed Date: 22 Nov 24 at 1:12PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Create bookmark tree using Delphi
Posted By: Rowan
Subject: Create bookmark tree using Delphi
Date Posted: 27 Mar 12 at 8:50AM
This sample code has been contributed by a Quick PDF Library customer.

//=================== START  Delphi 7 OutLine Code

tvOutLine:TTreeView;

// calling code is: 
                  GetAllOutlines(nil, QP.GetFirstOutline, 1, 3);

// this function is only needed to get the selected page number when dblclicking on the node
function FindLastChar(const S: AnsiString; Ch: Char = #32): Integer;
asm
  test  eax, eax
  jz    @@30
  mov  ecx, [eax - 4]
  test  ecx, ecx
@@10:
  jz    @@30
  mov  dh, [eax + ecx]
  cmp  dl, dh
  jne  @@20
  mov  eax, ecx
  inc  eax
  ret
@@20:
  dec  ecx
  jmp  @@10
@@30:
  xor  eax, eax
  dec  eax
end;


procedure TfrmPdfReader.GetAllOutlines(nNode: TTreeNode; id, level, maxlevel: Integer);
var
  inPage, inID: Integer;
  rNode, cNode: TTreeNode;
begin
  if (level > maxlevel) then
    exit;
  while (id <> 0) do
  begin
    inPage := QP.GetOutlinePage(id);
    rNode := tvOutLine.Items.Add(nNode, QP.OutlineTitle(id) + ' ' + ' p.' + IntToStr(inPage));
    inID := QP.GetFirstChildOutline(ID);
    if (inID <> 0) then
    begin
      cNode := tvOutLine.Items.AddChild(rNode, QP.OutlineTitle(inid) + ' ' + ' p.' + IntToStr(inPage));
      GetAllOutlines(cNode, QP.GetFirstChildOutline(id), level + 1, maxlevel);
    end;
    id := QP.GetNextOutline(id);
  end;
end;

procedure TfrmPdfReader.tvOutlineDblClick(Sender: TObject);
var
  inPos, inPage: Integer;
  stPage: AnsiString;
begin
  inPos := FindLastChar(tvOutLine.Selected.Text, '.');
  stPage := copy(tvOutLine.Selected.Text, inPos + 1, 4);
  if TryStrToInt(stPage, inPage) then
    RenderPageToImage(QP,inPage,ImgPreview,ZoomPercentage: Integer);
end;

// ============= END Delphi Outline code  ===========



Replies:
Posted By: ginganinja1
Date Posted: 25 Oct 12 at 1:58PM
Hi

I was wondering if it was possible to make the page number displayed in the tree view invisible as I don't wont them to show as the page numbers on my bookmarks do not correspond the the page numbers displayed in the PDF document.

Thanks


Posted By: Guy
Date Posted: 21 Jul 16 at 5:09AM
Having a problem with this code...

It adds the first node of each parent twice...any clues.

Guy



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk