how to read an specific page into pdf document?

Francis Nugent Dixon effendi at wanadoo.fr
Tue Oct 18 14:47:41 CDT 2011


Hi from beautiful Brittany,

Graham wrote :

> Where does the PDF page appear? I mean is it in a stack window,

> and could it be manipulated by a LiveCode program ?

The answer is YES !

I may be a little late on this thread, 'cos I've been trying
to solve the problem myself. I appear to have made progress
- to whit : pick up a page of a pdf file and get it as text
into a stack. Save it on an external file, then read it back
into the stack - Long-winded but effective.

Don't ask me what happens to non-text data in the page - I
haven't got that far, YET !

After playing about with Skim, and scanning all examples
available on the net, I think you can do just about anything
with Skim and AppleScript.

Of course, my example was developed on a MAC.

File "SkimTest1.pdf" contains text ONLY.
"MyPagesC" is a field containing the required page number.
"MySkim" is the reception field in my stack

TestStack available on request (save you coding it all up)

Be careful of line wraps.

Best Regards

-Francis


    put "tell application " & quote & "Skim" & quote into line 1 of  
GVMasterScript
    put "set " & LVDeskTop & " to path to desktop as string" into line  
2 of GVMasterScript
    put "open (" & LVDeskTop & " & " & quote & "SkimTest1.pdf" & quote  
& ")" into line 3 of GVMasterScript
    put "tell document 1" into line 4 of GVMasterScript
    put char 1 to 3 of field "MyPagesC" into GVPage
    put "go to page " & GVPage into line 5 of GVMasterScript
    put "set " & GVTextData & " to (get text for page " & GVPage & ")"  
into line 6 of GVMasterScript
    put "tell application " & quote & "TextEdit" & quote into line 7  
of GVMasterScript
    put "activate" into line 8 of GVMasterScript
    put "make new document" into line 9 of GVMasterScript
    put "set text of document 1 to GVTextData as text" into line 10 of  
GVMasterScript
    put "save document 1 in (LVDeskTop " & " & " & quote &  
"SkimOut.txt" & quote & ")" into line 11 of GVMasterScript
    put "end tell" into line 12 of GVMasterScript
    put "end tell" into line 13 of GVMasterScript
    put "activate" into line 14 of GVMasterScript
    put "end tell" into line 15 of GVMasterScript
    --
    --     AppleScript is now complete. So execute it !
    --
    do GVMasterScript as AppleScript
    put GVDeskTop & "/" & "SkimOut.txt" into LVSkimName
    if there is a file LVSkimName then
       open file LVSkimName
       put 0 into LVSkimLines
       repeat forever
          read from file LVSkimName until return
          put it into LVInputArea
          if LVInputArea is empty then exit repeat
          add 1 to LVSkimLines
          put LVInputArea into line LVSkimLines of field MySkim
       end repeat
       close file LVSkimName
       show field "MySkim"
    end if

"Nothing should ever be done for the first time !"








More information about the use-livecode mailing list