albertmaathuis Posted October 6, 2008 Share Posted October 6, 2008 Hi There, With the autoit window info executable (au3info.exe) which comes with the download it is possible to see the number of pages witin a PDF document. On the tab "summary" it gives i.e. 1 of 6 For my program i need to know how many pages a PDF document consists of. Is there a simple way of reading it from the document? If not perhaps i can extract it from au3info if the au3 file is available? Albert Link to comment Share on other sites More sharing options...
weaponx Posted October 6, 2008 Share Posted October 6, 2008 expandcollapse popup;' open the PDF in binary mode & count the pages ;' search for "/N xx" ;' or "/Count xx" MsgBox(0, "", pagecount("C:\Documents and Settings\mjhorn\My Documents\Documents\BRKCRT-1102_1213129245.pdf")) Func pagecount($sfilename) Local $c = 0 Local $pages = -1 ;'OPEN the PDF file $handle = FileOpen($sfilename,0) If @ERROR Then Return SetError(1,0,0) ;Get the data from the file Do $s = FileReadLine($handle) $EOF = @ERROR $c += 1 ;Look within the top 10 lines for /N If $c <= 10 Then If StringInStr($s, "/N") > 0 Then $array1 = StringRegExp($s,"/N\h(\d+)",3) $pages = Number($array1[0]) ExitLoop EndIf EndIf ;Check every line for /count If StringInStr($s, "/count") > 0 Then $array2 = StringRegExp($s,"/count\h(\d+)",3) $pages = Number($array2[0]) ExitLoop EndIf Until $EOF = -1 FileClose($handle) If $pages < 0 Then $pages = 1 Return $pages EndFunc ;==>pagecount Partially converted from:http://www.freevbcode.com/ShowCode.asp?ID=8153 Link to comment Share on other sites More sharing options...
albertmaathuis Posted October 7, 2008 Author Share Posted October 7, 2008 expandcollapse popup;' open the PDF in binary mode & count the pages ;' search for "/N xx" ;' or "/Count xx" MsgBox(0, "", pagecount("C:\Documents and Settings\mjhorn\My Documents\Documents\BRKCRT-1102_1213129245.pdf")) Func pagecount($sfilename) Local $c = 0 Local $pages = -1 ;'OPEN the PDF file $handle = FileOpen($sfilename,0) If @ERROR Then Return SetError(1,0,0) ;Get the data from the file Do $s = FileReadLine($handle) $EOF = @ERROR $c += 1 ;Look within the top 10 lines for /N If $c <= 10 Then If StringInStr($s, "/N") > 0 Then $array1 = StringRegExp($s,"/N\h(\d+)",3) $pages = Number($array1[0]) ExitLoop EndIf EndIf ;Check every line for /count If StringInStr($s, "/count") > 0 Then $array2 = StringRegExp($s,"/count\h(\d+)",3) $pages = Number($array2[0]) ExitLoop EndIf Until $EOF = -1 FileClose($handle) If $pages < 0 Then $pages = 1 Return $pages EndFunc ;==>pagecount Partially converted from: http://www.freevbcode.com/ShowCode.asp?ID=8153 Link to comment Share on other sites More sharing options...
albertmaathuis Posted October 7, 2008 Author Share Posted October 7, 2008 Thx very much, this works great!!! I'm using adobe reader 8.0, my friend 7.0 so i'm going to test it also on his PC Thanks again for the code. Albert Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now