Using Applescript to convert a PDF into PDF+Text

I need a way to convert a PDF in to a searchable PDF using AppleScript.

The commands that seem to do that are ‘convert image’ and ‘ocr’. Unfortunately, I can understand neither how to make them work nor the difference between the two.

According to the dictionary, both commands require:

  1. a direct parameter
  2. a record containing an image (for ‘convert image’) or an image file (for ‘ocr’)

Let’s assume that I have a simple PDF (unsearchable) in my Inbox.

tell application id "DNtp"
	tell database "Inbox"
		set u to content "Unsearchable"
		set s1 to convert image u -- what should I put here?
		set s2 to ocr u -- what should I put there?
		-- and what's the difference between the two?
	end tell
end tell

Could you please provide some examples of how to use both commands and a brief explanation?

Many thanks. W.

PS - the following post addresses a similar question, but the suggested solutions do not seem to work at all for me.
[url]OCR PDF]

convert image works on a record in the database
Convert image requires the term record before the reference to the record.

ocr works on a file specified by the path. (Though yes, you could use the path property of a record in the database.)
Ocr requires the term file before the file path.
The ocr command can be used to convert a file on your filesystem and have the PDF saved directly into a database.

Here is a simple example:

tell application id "DNtp"
	repeat with thisRecord in (selection as list)
		convert image record thisRecord -- For an internal record
		-- ocr file "/Users/myName/Desktop/myImage.jpg"
	end repeat
end tell

I get it now - thank you.

This is what I learned:

Both ‘ocr’ and ‘convert image’ are commands that work within the Application tell block but not within a Database tell block.

The dictionary entries for ‘ocr’ and ‘convert image’ wrongly imply that both functions have two required parameters, while in fact they have only one.

Any comment to deepen or rectify these insights would be welcome. In any case, my problem is solved and I am grateful the contributor who helped me.


<removed; bad advice>

Thank you for taking the time to reply, Korm.

Your comment explaining the standard syntax is well taken, and will undoubtedly save me much frustration in the future.

However, I still do not see how the dictionary for ‘OCR’ is not confusing. Indeed, it mentions that two parameters are required, a ‘direct parameter’ and a ‘file’, whereas in reality only one parameter is required.
This said, I notice that the ‘direct parameter’ appears first and is printed in italics. Maybe it means that ‘direct parameter’ is a generic term to designate the actual required parameter, ‘file’, which appears later in a regular font. I’ll pay more attention to such details in the future. It is very possible that the source of my confusion is my lack of experience with the conventions used in AppleScript dictionaries. I suspect that this forum is not the place to educate me in such matters, but I am still glad to have been given the opportunity to grow my understanding, no matter by how little. Thanks! W.

It’s not a bad place to learn but check out for the most valuable Applescript resource on the Internet.

Also, there are definite times you may want to address a database specifically. It all depends on the process you’re building.