Link to home
Start Free TrialLog in
Avatar of hschaake
hschaake

asked on

get string info

In any Acrobat '.pdf' file you can find the number of pages (/N) in the header
How do I retrieve this number and I want to output this number to another file in VB6
How do I programm this in VB??
Avatar of mcrider
mcrider

Go to http://wotsit.org/ and do a search on PDF.  The PDF file format is there...



Cheers!
Avatar of hschaake

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>      lBuf = Trim$(lBuf)

That's totally unuseful; as the number of pages is taken from bytes 4 to 7, ¿what is the idea about removing right blanks?

Viking,

Not totally unuseful... Some PDF writers in PDF 1.2 put spaces in the header to indent it.  If the spaces are not taken out, then the NEXT line does not properly work... As it stands, the code I proposed works on all versions of PDF files.

Cheers!
Clng() function works with trailing or leading spaces, or without them; so, I don't see the reason of trimming.

If line comes as

/N 100  (w/o spaces)

    or

/N 100  (with spaces)

the result will be exactly the same, as trailing blanks don't affect conversion functions.


vikiing,

You can't just do:  x=clng("/N 123")
or you will get "run-time error 13 type mismatch"

My code parses everything correctly and it works...

Besides, the trim is used a part of finding the "/N" line, not for doing the clng...


Cheers!
>>You can't just do:  x=clng("/N 123")

Of course, you can't; that's why you use Mid$(lbuf,3) to get rid of "/N", but I didn't question that point, my friend.

>My code parses everything correctly and it works...

Nobody said your code does not work (and yes, it does) but solely the use of Trim$() in Lbuf is totally unuseful. If you apply Clng() to Mid$(Lbuf,3), the argument to Clng() (w/o trimming)may contain:
a) A number (a sequence of digits) plus trailing blanks
b) A number, without blanks.

Both situations depends on if line has space filling or not. As Clng() (and many other conversion functions, like Val(), Cint(), Csng(), Cdbl(), etc.) do the same job, with or without trailing blanks, Clng() doesn't care if expression has blanks or not.

Under that point of view, ¿what is the benefit of trimming Lbuf before applying Clng()?

Yes, I know, now you'll say "the trim is fast, and it adds almost nothing". First of all: string-related procedures are always slow (more or less, depending on the length of the string), but, they're always lengthy operations. Sure, is adds ALMOST nothing of time; but if you are like me, a fighter against unuseful code, you would remove that dummy instruction, ¿wouldn't you?
vikiing, You still don't get it...

The header record of some versions of PDF look like this:

<<
Linearized 1
/O 2246
/H [ 14836 14346 ]
/L 5574625
/E 154780
/N 581
/T 5133644
>>
endobj

AND... Some look like this:
<<
     Linearized 1
     /O 2246
     /H [ 14836 14346 ]
     /L 5574625
     /E 154780
     /N 581
     /T 5133644
>>
endobj

If you are reading a PDF file that happens to be formatted in the second format, and don't do the trim, line 14:
   If UCase$(Left$(lBuf, 2)) = "/N" Then
WILL NOT PROPERLY FIND the /N record.


Cheers!
Thanks mcrider it's a very good answer on my question.
Glad I could help! Thanks for the points!


Cheers!
Good for McRider; now I've catched the way he spoke about justification.