I need to save a tiff as a pdf with apple preview.app

Hi all,
I need to use applescript to save a open tiff file in preview.app as a pdf.
I could not find a dictionary for preview.app.
Thanks in advance.

Hi

Sorry to be the bearer of bad news but preview isn’t really scriptable!
try looking into image events for what you wanna do!
post a few more details i’m sure someone will help!!

Hi,
do the tif files need to be open? If you have just a folder of tif’s you could give this a go!

on run
	set the_folder to choose folder with prompt "Select a folder containing tif files"
	the_conversion(the_folder)
	display dialog "Conversion complete!" with icon 2
end run

on open (dropped_items)
	set the_folder to item 1 of dropped_items
	the_conversion(the_folder)
	display dialog "Conversion complete!" with icon 2
end open

on the_conversion(the_folder)
	tell application "Finder" to set tif_list to every item of the_folder whose name ends with ".tif"
	repeat with this_item in tif_list
		set this_item to this_item as alias
		set convertCommand to "/System/Library/Printers/Libraries/./convert -f" & "\""
		set posix_path_of_this_item to lowercase POSIX path of this_item --> the command "lowercase" needs "TextCommands" scripting addition installed
		
		set thefile_string to this_item as string
		set new_file_string to characters 1 thru -4 of thefile_string & "pdf" as string
		set new_posix_path to POSIX path of new_file_string
		
		set convert_to_pdf to convertCommand & posix_path_of_this_item & "\"" & " -o " & "\"" & new_posix_path & "\"" & " -j \"application/pdf\""
		do shell script convert_to_pdf
	end repeat
end the_conversion

Hi blend,

for the lowercase conversion actually no additional scripting addition is needed


.
set posix_path_of_this_item to do shell script "echo " & quoted form of POSIX path of this_item & " | tr A-Z a-z"
.

PS: I guess, there is no lowercase conversion needed at all :wink:

Hi Stefan,
Thanks for the tip, My script was based on converting eps files to pdf but I found that if a file name ended with “.EPS” then the script errored, I changed the case of the filename and the errors went away.:confused:

Thanks, no the files do not need to open. it can happen sliently. Here is a little more detail. My clients have people fax info over to them. The fax turns the faxes into tiff images. Then it emails those images to a staff member. That person has a mail rules on there computer to dump all attachments into a folder on a file server. Then, about 8 staff review these files with adobe acrobat professional and convert them into pdfs. Most of the staff open them just to convert them into pdfs.

Hi,
from what you say there’s a couple of options open to you. You could have a folder action script that would convert the tif’s into a pdf open being added to the attachments folder, or a stay open application that would check the attachments folder every 30 seconds for new files and convert them to pdf. Once the tif has been converted can we delete these?
Nik

The folder action would be the best and yes we can delete the tif’s after the conversion.
Do you get the scripting additions off the developers cd.

Sorry about my lack of knowledge. But, I’m learning.

Thanks for you time.

Hi,
give this script a try

on adding folder items to this_folder after receiving added_items
	repeat with this_item in added_items
		set file_info to name extension of (info for this_item)
		if file_info contains "tif" then
			set convertCommand to "/System/Library/Printers/Libraries/./convert -f" & "\""
			set posix_path_of_this_item to POSIX path of this_item
			set thefile_string to this_item as string
			set new_file_string to thefile_string & ".pdf" as string
			set new_posix_path to POSIX path of new_file_string
			set convert_to_pdf to convertCommand & posix_path_of_this_item & "\"" & " -o " & "\"" & new_posix_path & "\"" & " -j \"application/pdf\""
			do shell script convert_to_pdf
			delete this_item
		end if
	end repeat
end adding folder items to

This script doesn’t require scripting additions but if you’d like to see what’s available you can check these out http://osaxen.com/.
Forgive me if you already know but the script needs to be saved into Macintosh HD/Library/Script/Folder Action Scripts folder and if you control click on the attachments folder a menu will appear, Select Configure Folder Actions… and add the attachments folder to the left hand window and select the script you’ve just saved in the right hand window. Once you’ve done this just drop some tiff files into the folder and once the tiff file has been deleted you should be able to open the pdf.
Nik

This works great! Can you help me with two issues.

  1. the extension ends up being .tif.pdf. Is there away to remove the .tif?
  2. when the convertion happens it only converts the first page. There might be mulitable page in one document.

Thanks again.

Hi,
to get rid of the double extension just replace

           set new_file_string to thefile_string & ".pdf" as string

with

set new_file_string to characters 1 thru -5 of thefile_string & ".pdf" as string

as for processing more than 1 page can you just clarify that you have a tif image with more than 1 page?
Nik

I can send you an example, but there is no way to attach a file. Can you send me an email at todd.dignan@newtechniques-online.com and I will send you a example file of what I talking about.

Thanks.

Thanks Nik,
That was the Trick, Thank you so much for your time and expertise.

on adding folder items to this_folder after receiving added_items
	set this_folder to this_folder as string
	repeat with this_item in added_items
		tell application "Finder" to set filename to the name of this_item
		set shortname to characters 1 thru -5 of filename as string
		set file_info to name extension of (info for this_item)
		if file_info contains "tif" then
			tell application "Adobe Acrobat 7.0 Professional"
				open this_item
				save document 1 to file (this_folder & shortname & ".pdf")
				close document 1
			end tell
			delete this_item
		end if
	end repeat
end adding folder items to