Get number of page of pdf

[quote=206881:@Denis Despres]Very good idea Michel
I just dont know how send 10 functions simultaneous
last time i’v tried ( another project… another circonstance )
they just wait for previous to end[/quote]

You must have used synchronous shell. If you use Mode 2, they should all execute as fast as you call. I will work on that and post a project later if it works as expected.

very very appreciate michel

Just a note:
macoslib contains CoreGraphics:CGPDFDocument. This class has also a “PageCount” method.
I did never use it but it should be possible to use that calss to get the needed information without any shell (or plugin).

I tried to use asynchronous shells, launching all at the same time to try and speed things up, unfortunately there seems to be limits to what an app can initiate. In practice, it is not faster than a synchronous one.

In terms of speed comparison, it probably is still quicker to use APIs to get at this information, the trouble is you then need to use additional APIs to convert the CF/NS objects into a format that you can use in Xojo, which adds additional overhead.

[quote=206879:@Christian Schmitz]Why not go with PDFKit or CoreGraphics on Mac?
We have a plugin for those or you try some declares.

Just opening the PDF and querying page count is not that difficult.[/quote]
In theory I would have expected MDItem (which I’m sure you have also) to be faster as this information has already been extracted from the PDF and stored in a Core Data database. The other advantage of using MDItem or equivalent is that it will also extract additional meta data for the file, which might be needed in the future.

This is of course opposed to opening the file, stepping through the file structure to find the right value and then extracting that.

I recently had the luxury of dealing with TNEF files, and at first I thought it was a well laid of format and reading the meta data that was needed would be easy… Until I found that theres multiple places for storing said meta data within the file and some of the structures are not as simple as they should be. I got what I wanted, but I’m also pretty certain that I’m not doing it right in one or two places.

Before I found CGImageProperties, I spent weeks working on code to read image meta data (IMDS), I have the full TIFF specification to hand, and yet not every application would create the meta data correctly, causing all kind of weird issues. I ended up with a folder full of corrupted JPEG images, simply because cameras and software didn’t follow the spec. I was so happy when I discovered CGImageProperties and being abstracted from the horrendous task. Nowadays I simply use MDItem, as it’s much quicker than CGImageProperties and for imaging purposes it even pulls out information about the pixels which are not stored in the image meta data :slight_smile:

Just for the records. Using macoslib you can just use following function to get the page count of a PDF:

[code]Function GetPDFPageCount(f as FolderItem) As Integer
dim targetURL as NSURL = NSURL.CreateWithFile(f)
dim pDoc as PDFDocument = PDFDocument.CreateFromURL(targetURL)

declare function pageCount lib CocoaLib selector “pageCount” (id as Ptr) as Integer
return pageCount(pDoc)

End Function[/code]

Very easy and no Plugin needed.

Thanks Thomas
I’m please with the “sh.Execute”
BUT… i’ll keep your solution and gone try it

For my knowledge… Using shell… it’s by plug in ???
I thought i’m using OSX Core info… so the very root info… not plug-in !!

MacOSLib and Shell are both without external plugins.

But technically the Xojo Shell is implemented as an internal plugin.