Friday, October 22, 2021

#1 2021-08-06 04:27:37 pm

Registered: 2019-10-23
Posts: 901

Get a strings from page number to end page in PDF

Simple example to get a string from PDF with fromPage number toPage number.


use framework "Foundation"
use framework "Quartz"
use scripting additions

set thePath to POSIX path of (choose file of type {"pdf"})
set theURL to current application's |NSURL|'s fileURLWithPath:thePath

its stringFromPDF:theURL fromPage:4 toPage:4
on stringFromPDF:theURL fromPage:pageBegin toPage:pageEnd
   set pdfDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
   set endCharacter to (pdfDoc's pageAtIndex:(pageEnd - 1))'s numberOfCharacters()
   (pdfDoc's selectionFromPage:(pdfDoc's pageAtIndex:(pageBegin - 1)) atCharacterIndex:0 toPage:(pdfDoc's pageAtIndex:(pageEnd - 1)) atCharacterIndex:(endCharacter - 1))'s |string|() as text
end stringFromPDF:fromPage:toPage:

if you are the expert, who will you call if its not your imagination.



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)