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: TXNole on Jun 06, '11 09:11:28AM

Will this work on Word documents? I have been looking for a way that I could automate the conversion of Word documents into PDFs with the "save as PDF" print screen.



[ Reply to This | # ]
Bulk convert text files to PDF
Authored by: tedw on Jun 06, '11 10:31:18AM
No. Well, possibly if the word documents are in rtf or text format, but not .doc files. there have been several hints about converting word documents to PDF (search the site), but the general problem seems to be that Word format is proprietary so Apple didn't include a conversion algorithm in CUPS (which is free under GNU license). the file types natively supported are listed here.

It doesn't seem impossible that someone could develop such support as a third party - the file at /usr/share/cups/mime/mime.convs seems to imply that local conversion configurations can be created, at any rate - but they'd still have to work out the proprietary software issue.

[ Reply to This | # ]

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 | # ]
Bulk convert text files to PDF
Authored by: musselrock on Jun 06, '11 12:07:42PM

For Word documents, either of these scripts, saved as applications, will batch Word files to PDF, The first uses Pages which I like to use the best as it preserves the hyperlinks in Word docs. The second script does it with Word (2008), but hyperlinks are lost.

First script:
(* Drag and drop batch conversion of Word docs or any document that can be opened by the Pages application to PDF files. *)

on open filist
tell application "Finder"
set defLoc to container of (item 1 of filist) as alias
end tell
set destn to choose folder with prompt "You are about to copy files to PDFs using Pages." & return & "Select a location to save the converted files." default location defLoc
repeat with lvar in filist
tell application "Finder"
set thename to name of lvar
set filex to name extension of lvar
set l to length of filex
end tell
set nuname to text 1 thru text item -(l + 1) of thename
tell application "Pages"
launch
set filname to (destn as string) & nuname & "pdf"
open lvar
save document 1 in filname
close every window saving no
end tell
end repeat
end open

Second script:
(*Batch convert Word files to PDF using Word 2008*)
on open fillist
set bs to "/"
set d to "-"
tell application "Finder"
set defLoc to container of (item 1 of fillist) as alias
end tell
set destn to choose folder with prompt "You are converting Word files by copying them to PDF files." & return & "Select a location to save converted files." default location defLoc
repeat with lvar in fillist
tell application "Finder"
set thename to name of lvar
set filex to name extension of lvar
set l to length of filex
end tell
set nuname to text 1 thru text item -(l + 1) of thename
if "/" is in nuname then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to bs
set txtLst to every text item of nuname as list
set AppleScript's text item delimiters to d
set nuname to txtLst as string
set AppleScript's text item delimiters to oldDelims
end if
set filname to (destn as string) & nuname & "pdf"
tell application "Microsoft Word"
launch
open lvar
save as active document file name filname file format format PDF
close window 1 saving no
end tell
end repeat
end open



[ Reply to This | # ]