We have pdf stores in container field. Is there a way to count the number of pages of these pdf ?
Seems like all the information I've found on the internet indicate that the number of pages is not contained in the pdf metadata, which I find hard to believe!
If the pdf's are generated from filemaker - this is a different story, but if there are random pdf's placed into the container in filemaker, then it might just simply come down to "guess work". If all the pdf's are of similar content, then the file size might be the only way to "guess" the number of pages.
Sorry, that's all I've found so far.
Couple of options - some of which cost more than others
Write your own function with ScriptMaster and iText
Scribe doesn't seem to do it
PDFManipulator - PCPF_GetNumPages
If you're on OSX you could use Applescript. The file would need to be exported to a temporary path.
Pdf has quite some metadata stored which you can access with a command: mdls.
Here's a simple example that lets you select the file and get the number of pages.
tell application "SystemUIServer"
set f to POSIX path of (choose file)
set pages to do shell script "mdls -name kMDItemNumberOfPages " & f
I use pdftk.exe (in windows OS). It's very useful tool for manipulate pdf files.
I create a command line with this parameters:
pdftk.exe xxxx.pdf dump_data | findstr NumberOfPages
You can download the (free) tool on : https://www.pdflabs.com/docs/pdftk-man-page/
You can also get the number of pages by parsing the result of this calculation:
Base64Decode ( Base64Encode ( container ) )
Actually, I would create a recursive custom function.
can you explain how it functions with an example?
"can you explain how it functions with an example?"
PDFPageCount ( container )
2015/09/22 v. 1
t = Base64Decode ( LeftValues ( Base64Encode ( container ) ; 5 ) ) ;
start = Position ( t ; "/N " ; 1 ; 1 ) + 3 ;
end = Position ( t ; "/T" ; start ; 1 )
If( not PatternCount ( t ; "Linearized" ) ; "This PDF isn't Linearized; maybe the result is wrong ¶" ) & Middle ( t ; start ; end - start )
As you say, ONLY works for linearised PDF files
A linearized PDF file is a special format of a PDF file that makes viewing faster over the Internet.
That is when you select an option like Fast Web View when creating the file in the first place. And FileMaker doesn't as it happens. And this is because to stream the file it need sot know how many pages are coming before it starts.
The other ways above provide a reliable result each and every time, regardless of creation method.
It does not work properly. I get the message "This is not linearized PDF"
It works properly.
Just using this method it will not give you a number of pages, except for small subset of PDF files.
Your PDF file is NOT linearized.
can you send a pdf file or tools for linearized pdf?
The start of two PDF files illustrate this completely
2 0 obj
<</Length 3 0 R/Filter/FlateDecode>>
299 0 obj
<</Linearized 1/L 59486/O 301/E 37830/N 4/T 53385/H [ 1239 301]>>
You are way past what FileMaker can do natively now, and so using one of the other methods will get you a quicker result. NO point at all trying to linearize a file just so you can use that method to extract total pages.
If you insist
PDF linearization (optimization), linearized PDF file, Optimize PDF for fast Web viewing
its command line, but could do what you want. But again. Why?
To Linearize a pdf simply open it and save it with Acrobat Reader DC
Could you give me more lines of the first example ?
Thanks, i have save the file with Acrobat Reader. Now the function calculate the correct number of pages.
Because I like to understand how to properly use the suggestions
Why not export the file, open it automatically, then look at the page count and enter it into the database. Fewer mouse clicks.
Thank you Daniele. This works for me as most of our pdf are linearized.
I think this custom function will solve the majority of cases.
See the attachment.
Thank you. that would have taken me a long time to come up with that function. Works great!
Retrieving data ...