Re: PDFSelection from a range
Re: PDFSelection from a range
- Subject: Re: PDFSelection from a range
- From: Matthew Weinstein <email@hidden>
- Date: Sat, 5 Jun 2010 19:23:20 -0700
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, email@hidden 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 (email@hidden)
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:
This email sent to email@hidden