Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Bulk convert text files to PDF' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bulk convert text files to PDF
Authored by: musselrock on Jun 06, '11 12:50:53PM

I forgot about textutil which is application independent. Search this forum for "textutil" looking under OS X 10.4. Lots of good hints.



[ Reply to This | # ]
Bulk convert text files to PDF
Authored by: tedw on Jun 06, '11 01:56:52PM
well, I'd forgotten about textutil as well. You could convert doc and docx files to pdf indirectly by first converting them to rtf format, with the following modifications:
on open theFiles
	set oldTID to AppleScript's text item delimiters
	repeat with thisFile in theFiles
		-- get file path as posix path
		set inputFilePath to POSIX path of thisFile
		
		set AppleScript's text item delimiters to "."
		-- check for doc & docx, convert them to rtf, reset inputFilePath to point to converted file
		if last text item of inputFilePath is in {"doc", "docx"} then
			do shell script "textutil -convert rtf " & quoted form of inputFilePath
			set inputFilePath to ((text items 1 thru -2 of inputFilePath) & "rtf") as text
		end if
		
		-- create output path - same name with .pdf extension
		set outputFilePathBits to text items of inputFilePath
		set last text item of outputFilePathBits to "pdf"
		set outputFilePath to outputFilePathBits as text
		
		-- create convert command and send to shell
		set AppleScript's text item delimiters to " "
		set cmdList to {"/System/Library/Printers/Libraries/convert", "-f", quoted form of inputFilePath, "-o", quoted form of outputFilePath}
		do shell script (cmdList as text)
	end repeat
	set AppleScript's text item delimiters to oldTID
end open
That might lose or mess up some formatting - not everything in a doc file can be represented properly in rtf - but it might do for quick and dirty conversions. Probably it should clean up the intermediary rtf files, too, but...

[ Reply to This | # ]