Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions PdfPageCount.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*******************************************************************************)

////////////////////////////////////////////////////////////////////////////////
// Summary of steps taken to parse a PDF doc for its page count :-
// Summary of steps taken to parse a PDF doc for its page count :-  
////////////////////////////////////////////////////////////////////////////////
//1. See if there's a 'Linearization dictionary' for easy parsing.
// Mostly there isn't so ...
Expand Down Expand Up @@ -39,6 +39,7 @@ interface
PDF_ERROR_FILE_OPEN = -2;
PDF_ERROR_FILE_FORMAT = -3;
PDF_ERROR_ENCRYPTED_STRM = -4;
PDF_ERROR_NO_INDEX = -5;

(*******************************************************************************
* GetPageCount *
Expand Down Expand Up @@ -902,6 +903,7 @@ function TPdfPageCounter.GetPageNumUsingCrossRefStream: integer;
//if the Index array is empty then use the default values ...
if length(indexArray) = 0 then
begin
Result := PDF_ERROR_NO_INDEX;
setLength(indexArray, 2);
indexArray[0] := 0;
indexArray[1] := bufferSize div (w1 + w2 + w3);
Expand Down Expand Up @@ -950,7 +952,8 @@ function TPdfPageCounter.GetPageNumUsingCrossRefStream: integer;

DisposeBuffer;

QuickSortList(PdfObjList.List, 0, PdfObjList.Count -1, ListSort);
if PdfObjList.Count > 1 then
QuickSortList(PdfObjList.List, 0, PdfObjList.Count -1, ListSort);
if not GotoObject(rootNum) then exit;
if not FindStrInDict('/Pages') then exit;
//get the Pages' object number, go to it and get the page count ...
Expand Down Expand Up @@ -1057,7 +1060,8 @@ function TPdfPageCounter.GetPdfPageCount(stream: TStream): integer;
//Make sure we've got Root's object number ...
if rootNum = $FFFFFFFF then exit;

QuickSortList(PdfObjList.List, 0, PdfObjList.Count -1, ListSort);
if PdfObjList.Count > 1 then
QuickSortList(PdfObjList.List, 0, PdfObjList.Count -1, ListSort);
if not GotoObject(rootNum) then exit;

if not FindStrInDict('/Pages') then exit;
Expand Down Expand Up @@ -1122,3 +1126,4 @@ function GetPageCount(const filename: string): integer;
//------------------------------------------------------------------------------

end.