A solution to my own problem. This is from a category I created for 
PDFDocument. Seems to work. The + and - 1's are strictly trial and error. Seems 
to work, even with some pretty complex PDFS (created by comicLife, for 
instance). Probably not the pithiest way to do this (ans is completely 
superfluous) but for the record:

-(PDFSelection *) selectFrom: (int) b to: (int) e
{
        int bspot, espot;
        int i, n;
        int flag, totlen, plen;
        PDFPage *bpage, *epage, *tpage;
        PDFSelection *ans;
        totlen=flag = 0;
        if(!(b < e)) return nil;
        n = [self pageCount];
        for(i = 0; i< n; i++)
        {
                tpage = [self pageAtIndex: i];
                plen = [[tpage string] length];
                if(b < totlen + plen)
                {
                        flag++;
                        bpage = tpage;
                        bspot = b - totlen;
                }
                if(b < totlen + plen)
                {
                        flag++;
                        bpage = tpage;
                        bspot = b - totlen;
                }
                if(e <= totlen + plen)
                {
                        flag++;
                        epage = tpage;
                        espot = e - totlen - 1;
                }
                if(flag >= 2) break;
                totlen += (plen + 1);
                
        }
        if(flag < 2) return nil;
        ans = [self selectionFromPage: bpage atCharacterIndex: bspot toPage: 
epage atCharacterIndex: espot];
        return ans;
}



On Jun 5, 2010, at 7:16 PM, cocoa-dev-requ...@lists.apple.com wrote:

> Dear programmers,
> I think I must be missing some simple method in the api to do this, but, 
> given a range of a PDFDocument string, how do I convert that to a selection? 
> I found the PDFPage selection from range, but how do I find what pages a 
> selection for the document string covers?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to