Script to Convert Batch of PDFs to TIFFS or flat PDFs

Hi,
i am trying to take a folder of pdfs that have text in them and convert them to either flat pdfs (no text embedded) or just tiffs. the automator actions I can't seem to get to work, well, the render to image action for pdfs does not seem to do anything at all. is there a way I can do this using applescript, or am i missing something in automator that will work. any help is appreciated, this should be simple enough.
chris

powerbook G4, Mac OS X (10.4.6)

Posted on May 26, 2006 2:12 PM

Reply
11 replies

May 27, 2006 9:26 AM in response to Chris Nidel

Chris,

Here is an AppleScript that can be used to replace all of the text in a "Run AppleScript" Automator action that will do what you want. You will also have to download "Imagine Photo" that is a freeware application to do the conversion. I have modified the scripts that were available from that site. It is located here:

http://www.yvs.eu.com/imaginephoto.html

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property thePDFFolder : ((path to desktop) as string) & "PDF Folder"
property theExportFolder : ((path to desktop) as string) & "TIFF Folder" as alias
property exportType : "TIFF"
property theFileExtension : ".tif"

to RemoveFileExtension(fileName)
set tids to (AppleScript's text item delimiters)
set AppleScript's text item delimiters to {"."}

set NbTxtItems to count of text items of the fileName
if NbTxtItems is greater than 1 then
set newFileName to ((text items 1 thru -2 of the fileName) as string)
else
set newFileName to ((text item 1 of the fileName) as string)
end if

set AppleScript's text item delimiters to tids
return newFileName
end RemoveFileExtension

on run {input, parameters}
tell application "Finder"
set theFiles to the items of folder thePDFFolder
repeat with thisFile in theFiles
set thisFileRef to thisFile
set thisFileName to name of thisFileRef
set thisFileName to my RemoveFileExtension(thisFileName)
tell application "iMagine Photo"
set thisImporter to import graphic thisFileRef as alias
if the component error of thisImporter is not equal to 0 then
close thisImporter
return
end if
tell thisImporter to make exporter with properties {export file type:exportType, export folder location:theExportFolder, export file name:(thisFileName & theFileExtension)}
export thisImporter
close thisImporter
end tell
end repeat
end tell

return input

end run
</pre>


PowerBook 12" Mac OS X (10.4.6)

May 28, 2006 10:05 PM in response to Chris Nidel

Chris,

According to the documentation on Imagine Photo the default resolution for the tiff graphics exporter is 72 but that can be adjusted.

So I am hoping it just needs to be bumped up to get what you want.

I have added into the command the flexibility to change the generated resolution. Just adjust the values for XResolution and YResolution at the top of the script to what you want and try that.

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property thePDFFolder : ((path to desktop) as string) & "PDF Folder"
property theExportFolder : ((path to desktop) as string) & "TIFF Folder" as alias
property exportType : "TIFF"
property theFileExtension : ".tif"
property XResolution : 72.0
property yResolution : 72.0

to RemoveFileExtension(fileName)
set tids to (AppleScript's text item delimiters)
set AppleScript's text item delimiters to {"."}

set NbTxtItems to count of text items of the fileName
if NbTxtItems is greater than 1 then
set newFileName to ((text items 1 thru -2 of the fileName) as string)
else
set newFileName to ((text item 1 of the fileName) as string)
end if

set AppleScript's text item delimiters to tids
return newFileName
end RemoveFileExtension

on run {input, parameters}
tell application "Finder"
set theFiles to the items of folder thePDFFolder
repeat with thisFile in theFiles
set thisFileRef to thisFile
set thisFileName to name of thisFileRef
set thisFileName to my RemoveFileExtension(thisFileName)
tell application "iMagine Photo"
set thisImporter to import graphic thisFileRef as alias
if the component error of thisImporter is not equal to 0 then
close thisImporter
return
end if
tell thisImporter to make exporter with properties {export file type:exportType, export folder location:theExportFolder, export resolution:{XResolution, yResolution}, export file name:(thisFileName & theFileExtension)}
export thisImporter
close thisImporter
end tell
end repeat
end tell

return input

end run
</pre>

PowerBook 12" Mac OS X (10.4.6)

May 29, 2006 12:52 PM in response to lc55

lc55,
thanks for your efforts. i am not sure what is wrong. it seems the render is poor. i bumped it up to 300 dpi and i still get garbled looking text. not sure what do do next. it seems like it is something in imagine photo, but i am far from knowing for sure, just seems odd that the quality does not improve at higher res.

if anyone has any further ideas, please don't hesitate. it seems that a preview command should work, but i have not had luck with the image view library.
chris

May 30, 2006 1:06 PM in response to lc55

well, the saga of the simple problem continues. i tried on my desktop (dual 2.5) and get the same result. I tried changing the bit depth, thinking that maybe there is a problem on that front. no dice. I end up with fouled up fonts in the end. I tried graphic converter, and that was not wanting to work for some reason, even though it said it would create multipage tiffs. Preview seems like it works fine, the problem is that it only exports the first page of the pdf in the tiff. This seems like a simple conversion, but is proving to be a bear.

Perhaps there is another way to strip the text from a pdf...anyone...anyone?

I thought the tiff approach would be easy as that won't support the text anyway, but so far, no dice.

thanks.
chris

Jun 9, 2006 2:01 PM in response to lc55

Could you implement something similar to this to combine multiple JPGs into a multipage PDF using the Terminal-command-line convert utility from the fink-installed ImageMagick software? Can you run Terminal.app commands from within Apple Script without having to open a Terminal window?

And possibly use the AppleScript as a folder-action-script to process a batch of JPGs that you drop on it, then open the PDF in Preview?

Jun 9, 2006 4:16 PM in response to Glen Doggett

Glen,

Thanks for reminding me to get back to Chris.

Yes this is possible.

In fact you can use Preview to produce a multipage PDF if you want.

Preview method
************
To see if this suits you needs just do the following:
Under the Images tab in Preview Preferences you will find a choice of "Open groups of images in the same window". With this selected you can then just select multiple jpgs in the Finder and double click them and they will appear as a single document in Preview. They can then be saved. This can all be automated in AppleScript/Automator.

Shell method
**********
If you wish to use the Terminal command line approach you can likely use the "Do shell script" AppleScript command or the "Run Shell Script" Automator action which send the script to the shell without opening a terminal window.

I have previously developed a script that took jpg images manually downloaded from a tethered camera and with a folder action moved them to preview in a manner similar to above to produce a slide-show in Preview.

That discussion is located here:

http://discussions.apple.com/thread.jspa?threadID=497247&tstart=0


Let me know if you need any further help.

PowerBook 12" Mac OS X (10.4.6)

Jun 15, 2006 8:28 PM in response to lc55

I didn't know Preview could do this also.
In fact you can use Preview to produce a multipage
PDF if you want.

I tried, but for some reason, Save As... and Print...to PDF File only output the active displayed image in the group of opened images. I checked my prefs. Not sure what I'm doing wrong. I can't get multi-page PDF output from a group of single-page jpg images in Preview.

But
convert *.jpg bundle.pdf

works for me.

Jun 15, 2006 8:50 PM in response to Chris Nidel

Chris,

Sorry for the delay. Been rather busy and forgot that I left you sort of hanging.

I happened to find a script tonight that might help with your situation if you just want to strip the text out of the PDF's. It is just an automation using GUI scripting of a simple "Select All" and "Copy" to the clipboard and then you transfer the clipboard contents to another application such as a simple text editor or word processor. This script does get the text in the whole document and not just the visible page.

It is located on the MacScripter's Website at the following URL:

http://bbs.applescript.net/viewtopic.php?id=14947

Let me know if want help in implementing it for your case.

Jun 20, 2006 1:00 PM in response to Chris Nidel

Hello Chris,
Did you try to do this in Photoshop?
I have this script abouve that do this to me.
Maybe this works well
Good Luck


tell application "Finder"
activate


--DEFINIçÕES DE CAMINHOS
set disco to name of startup disk
set lar to name of home
set caminho_lar to disco & ":users:" & lar
set pasta_inicio to "1-inicio"
set caminhodapasta to disco & ":users:" & lar & ":Desktop:"
set caminhomeio to caminhodapasta & "2-meio"
set caminhofim to caminhodapasta & "3-fim"
set caminho1 to folder "Desktop" of folder lar of folder "Users:" of startup disk

--PASTA ONDE OS ARQUIVOS SERÃO COLOCADOS
set the pasta_inicio to the folder "1-inicio" of folder "Desktop" of folder lar of folder "Users" of startup disk
--PASTA DE TRABALHO DO PS
set the pasta_meio to the folder "2-meio" of folder "Desktop" of folder lar of folder "Users" of startup disk

--ABRE A ROTINA DE CÓPIA E TROCA DE NOME PARA CADA ARQUIVO
set arquivos to every item of pasta_inicio
copy arquivos to lista
repeat with i from 1 to the count of arquivos
set this_file to item i of lista
set nomealvo to the name of this_file
-- display dialog nomealvo
select this_file
set alvo to move this_file to caminhomeio
set name of alvo to "alvo"

--CRIA PASTA COM NOME ORIGINAL DO ARQUIVO PARA RECEBER O MATERIAL CONVERTIDO
set xanadu to make new folder at caminhofim with properties {name:nomealvo & "_folder"}


--CHAMA ACTION NO PS
tell application "Adobe Photoshop CS"
do action "Pdf" from "Pdf to Psd"
end tell

--COPIA ARQUIVOS CONVERTIDOS PARA A PASTA COM O NOME DO MESMO
set prontos to select (every file of the pasta_meio)
move prontos to xanadu


end repeat


end tell

end adding folder items to

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Script to Convert Batch of PDFs to TIFFS or flat PDFs

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.