- Code: Select all
tell application "PDFpenPro"
open theFile as alias
tell document 1
ocr
repeat while performing ocr
delay 1
end repeat
delay 1
close with saving
end tell
end tell
The sample code from the makers of PDFPen for splitting PDFs is more complex, it allows you to choose an output location, which I don't need. I simply wish to split a PDF, outputted to a location coded into the script, when the source PDF matches my conditions. .
- Code: Select all
-- Split PDF script / droplet
--
-- Split the current document in PDFpen into one PDF file per page
on split(aDocument)
tell application "PDFpenPro"
set savePath to choose folder with prompt "Store new PDF files here:"
set docName to name of aDocument
if docName ends with ".pdf" then
set docNameLength to (length of docName)
set docName to (characters 1 thru (docNameLength - 4) of docName as string)
end if
set pageCount to 1
set originalDoc to aDocument
repeat with aPage in pages of originalDoc
set newDoc to make new document
copy page pageCount of originalDoc to end of pages of newDoc
set fullSavePath to (savePath as rich text) & docName & "_"
set zeroCount to 3
if (pageCount div 10) > 0 then
set zeroCount to 2
end if
if (pageCount div 100) > 0 then
set zeroCount to 1
end if
if (pageCount div 1000) > 0 then
set zeroCount to 0
end if
repeat zeroCount times
set fullSavePath to fullSavePath & "0"
end repeat
set fullSavePath to fullSavePath & pageCount & ".pdf"
-- The try block is necessary to avoid a sandbox issue
try
close document 1 saving in fullSavePath
end try
set pageCount to pageCount + 1
end repeat
return pageCount - 1
end tell
end split
on run
tell application "PDFpenPro"
if (count documents) > 0 then
return split(document 1) of me
else
return
end if
end tell
end run
on open fileList
repeat with aFile in fileList
set totalPages to 0
tell application "PDFpenPro"
open (aFile as alias)
set aDocument to document 1
set totalPages to totalPages + (split(aDocument) of me)
close aDocument
end tell
end repeat
end open
I've been trying for a week or so, but I just dont understand what I'm doing here. Could someone help please?
Many thanks,
Mark.
PS. Alternative solutions also welcome if PDFPen isn't the best way to do this
