36
16
How do I batch convert many Word documents and have them saved as [originalfilename].pdf?
36
16
How do I batch convert many Word documents and have them saved as [originalfilename].pdf?
24
This is how I would do it:
Only downside is that you have to click Ok once for each file.
The same workflow can be used with PDFCreator (http://en.pdfforge.org/pdfcreator). If you install it as a service or in automatic mode it is hands off except for select > print.
– matt wilkie – 2010-07-13T21:01:06.5303This was what I actually did. I had to do it a little differently though... I openend the CutePDF "Printer" from the control panel, so it showed what would be the printer-queue... Then I dragged and dropped the documents into that window - and then it was all pounding on ENTER to accept the filename from there... They were all named MICROSOFT WORD - [filename].pdf, but I can solve that easily. – Kjensen – 2009-08-04T00:26:40.250
1If I highlight more than 15 files in Windows the 'Print' option disappears from the right-click context menu. I've just tried the drag n drop method, but 94 files might just be too much for it... – Spacedman – 2012-02-23T13:43:42.077
41
This might be pushing it into stackoverflow.com territory, but you could script Word 2007 to open and save a document as PDF. This requires Office 2007 and the "Save as PDF" plug-in from Microsoft.
Save this to a file SaveAsPDF.js
and run it from the command line using cscript.exe //nologo SaveAsPDF.js SomeFolder\MyDocToConvert.doc
:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
docPath = fso.GetAbsolutePathName(docPath);
var pdfPath = docPath.replace(/\.doc[^.]*$/, ".pdf");
var objWord = null;
try
{
WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
objWord = new ActiveXObject("Word.Application");
objWord.Visible = false;
var objDoc = objWord.Documents.Open(docPath);
var wdFormatPdf = 17;
objDoc.SaveAs(pdfPath, wdFormatPdf);
objDoc.Close();
WScript.Echo("Done.");
}
finally
{
if (objWord != null)
{
objWord.Quit();
}
}
@bobbymcr Link in answer is dead. See here for current SaveAsPDF
plugin download.
5
The above code works excellently but it only takes one file as an argument. I was too lazy to look up a way to filter a directory in JScript, so I cooked up a way in Powershell using below post as inspiration: http://stackoverflow.com/questions/181036/powershell-run-a-program-in-a-foreach/181065 PS E:\MyDocuments> ls *.doc | %{cscript //nologo E:\jssrc\SaveAsPDF.js $_}
– Aniti – 2012-09-04T08:12:00.8639
well, cutepdf & pdf99 do their job well, but i find PDFcreator more appealing as it 'print's in higher quality than the other two, it also has more configuration option, plus it's open-source.
1PDFCreator can be used as answered by kjensen above, however, I wanted to point out that in the PDFCreator options, you can enable auto-save, which will automatically save each document in the directory of your choosing with the filename of your choice as well. That way you don't need to hit "enter" to verify that you want to save each file. – None – 2010-09-15T13:20:13.400
6
Regarding the SaveAsPDF.js script that a previous user posted. This worked for converting one pdf file, but i didnt know how to covert all the files in a directory. With a little playing I created a file. CovertAll2PDF.bat with the following 2 lines:
echo off
for %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js "%%X"
there is also the /r "Parent Directory"
which can be inserted as for /r "PD" %%X in -....
which will go through all the directories, in that case make it C:\SaveAsPDF.js and save Saveaspdf.js in that directory.
I'm sure its clumsy, but it worked for me. hope this helps someone.
6
Use Google Docs as a Batch PDF Converter by Amit Agarwal
If you have a huge bundle of Word Documents, Excel Spreadsheets and PowerPoint Presentations on your hard drive that you would like to convert into PDF at once without investing in commercial software like Adobe Acrobat, try Google Docs.
While it has always been possible to convert Office documents into PDF using Google Docs, the new export feature makes it even easier for you to batch convert Microsoft Office and OpenOffice file formats into PDF (or HTML) in three easy steps. Batch Conversion to PDF with Google Docs
Use Google Docs as a Batch PDF Converter
Step #1 - Create a new "input" folder in Google Docs where you'll upload all your documents and presentations that are to converted into PDF.
Step #2 - Now select the Upload Document option in Google Docs, set the destination folder to the one that you created in Step #1 and upload* all your documents.
Google Docs officially supports the following file formats though you may also upload images:
* Microsoft PowerPoint (.ppt, .pps).
* Microsoft Word (.doc, .docx), OpenDocument (.odt) and StarOffice (.sxw).
* Microsoft Excel (csv, .xls, .xlsx) files and OpenDocument Spreadsheet (.ods).
[*] You may also use the email option to upload documents onto Google Docs but that would put everything on the main folder and managing documents can therefore become a issue especially when you have too many files.
Step #3 - Once all files are uploaded onto Google Docs, open the dashboard again and select the "input" folder from the right sidebar. Select all the files in this folder and choose "Export" under "More Options".
Here's select "PDF" (or HTML) as the output format and all your Word Documents, presentations, spreadsheets, etc. will be instantly converted into PDF.
And if you are converting a large batch of documents into PDF, you don't have to wait in the browser for the conversion to finish as Google Docs will automatically send you an email once the processing is over. The email will have a link from where you can directly download all the PDF files in one large ZIP.
This method is originally from 2009 and unfortunately appears to have been removed (individual files can be exported as pdf, but folders no...) – Joe – 2016-12-20T12:35:37.123
1Be prepared for significant mangling of any document that contains tables, images, less common fonts. I haven't dived into it further, but I tried a word document with a letterhead constructed with a table containing text and a graph, and using the Calibri font. The PDF was nothing like the original. – rossmcm – 2013-08-02T00:48:38.890
6
Bobbymcr's answer is pretty interesting and works well with Word 2010. Still, there's an improvement to be made. Bobbymcr's original command line looks like this:
cscript.exe //nologo SaveAsPDF.js SomeFolder\MyDocToConvert.doc
This doesn't work if you have associated .js files with some kind of editor like Notepad++. In this case you also have to specify the engine to use, otherwise cscript will show you an error message. This is easily achieved by using the //E:jscript
command line parameter:
cscript.exe //nologo //E:jscript SaveAsPDF.js SomeFolder\MyDocToConvert.doc
4
This little snippet worked very well for me.
No limits on number of files
$Word=New-Object -ComObject Word.Application
$Files=Get-ChildItem ".\*.docx"
ForEach ($File In $Files) {
$Document=$Word.Documents.Open($File.FullName)
$Name=($Document.FullName).Replace("docx", "pdf")
$Document.SaveAs([ref] $Name, [ref] 17)
$Document.Close()
}
$Word.Close()
Just save it to a PowerShell script like Convert-Documents.ps1
and then run it from the command line from within the folder where all your source documents are located.
There was an edit made by @cxw to my answer, which removed significant parts of my answer, namely, the fact that the script is free
and can process and unlimited
number of files. As such, I rolled-back the edit, but have incorporated the syntax-fix suggested in the edit. – Umar Farooq Khawaja – 2017-08-31T16:36:47.043
It worked for me under Windows 7 when I took the [ref]
commands and the last line ($Word.Close()
) away. Otherwise errors appeared. – loved.by.Jesus – 2018-03-21T15:04:45.523
4
I've not tried it but there is a batch method using OpenOffice.org that you could test. Instructions on doing this on GNU/Linux and Windows platforms described at http://www.tech-faq.com/convert-word-to-pdf.shtml (and also at http://www.togaware.com/linux/survivor/Convert_MS_Word.html" and, at http://www.oooforum.org/forum/viewtopic.phtml?t=3772).
The principle of using OpenOffice.org to read in the .doc file and then export it as a PDF seems sound if you find OpenOffice.org makes areasonable job of opening the .doc files you have.
1
Using OpenOffice.org will give you clickable table of contents and so on. Any "Print to PDF" solution won't. See http://superuser.com/questions/568/how-to-print-documents-to-pdf/744#744
– Arjan – 2009-08-03T18:50:20.343+1 for pdf virtual printers. Those are great, I wish they would be available by default on every OS. – Manu – 2009-08-14T09:39:26.190
1
A slightly easier alternative compared to the Powershell, Batch, and Windows Script Host scripts above is the docx2pdf
tool which works on both Windows and MacOS: https://github.com/AlJohri/docx2pdf/
Similar to other answers, this approach uses win32com in Windows and JXA (Javscript for Automation, basically AppleScript in JS) in macOS. However, it is packaged up into an easily installable and ready to batch convert package with a progress bar.
Install:
pip install docx2pdf
Run:
docx2pdf myFolderOfWordDocs
Disclaimer: I wrote this tool after struggling to find a cross-platform solution for batch converting docx to pdf with zero formatting issues since it directly uses Microsoft Word.
0
If you want a quick and simple online method for 20 or less files then use this website online2pdf, here you can upload your files, choose some options and then click convert, it will convert all the documents and then automatically download a single zip file containing the PDF files.
0
Building off of Umar's answer, here is a modified PowerShell script that will:
As with Umar's, to use this:
doc2pdf.ps1
, somewhere in your PATH
powershell doc2pdf.ps1
$Word=New-Object -ComObject Word.Application
$Files=@(Get-ChildItem ".\*.docx") + @(Get-ChildItem ".\*.doc")
# Need @() to get an array in case there is only one file - see
# https://blogs.technet.microsoft.com/heyscriptingguy/2013/07/18/powertip-find-number-elements-in-a-powershell-array/#comment-104863
for($file_idx = 0; $file_idx -lt $Files.Count; ++$file_idx) {
# Show the current progress
$File = $Files[$file_idx]
Write-Progress -Activity "Convert DOC(X) to PDF" `
-CurrentOperation $File.Name `
-PercentComplete (($file_idx/$Files.Count)*100)
# Make the PDF
$Document=$Word.Documents.Open($File.FullName)
$Name=($Document.FullName -replace "\.docx?", ".pdf") # -replace is case-insensitive regex per https://ss64.com/ps/syntax-regex.html
$Document.SaveAs([ref] $Name, [ref] 17)
$Document.Close()
}
# Clean up
$Word.Quit() # Doesn't close other Word instance that may be running.
# Remove any dangling references, per https://technet.microsoft.com/en-us/library/ff730962.aspx
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Word)
Remove-Variable Word
# By cxw - https://superuser.com/users/269989/cxw - CC-BY-SA 3.0
# Modified from https://superuser.com/a/1187598/269989 by https://superuser.com/users/12797/umar-farooq-khawaja
Tested with Word 2013 and PowerShell 4.0.
0
Converting multiple documents from DOC to PDF on Windows XP using JODConverter and Open Office
Prerequisites:
Step 1 Download JODConverter (latest version jodconverter-2.2.2.zip) from
Uncompress JODConverter zip file in a directory of your choice (D1)
Step 2 Start OpenOffice in service mode (more details here)
Create a batch file start-service.bat with the following content:
start-service.bat:
X:\Program Files\OpenOffice.org 3\program\soffice.exe -headless
-accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard
::if doesn't work try removing this last parameter(–nofirststartwizard)
(assuming X:\Program Files\OpenOffice.org 3\ is the directory where Open Office is installed and soffice.exe is present).
Run start-service.bat (open office is now started in service mode and awaiting commands)
Step 3
Collect all documents to be converted to pdf in a directory (D2)
Create a batch file convert.doc which launches JODConverter with and issue the conversion instructions:
convert.bat:
java -jar "<D1>\lib\jodconverter-cli-2.2.2.jar" -f pdf *.doc
where D1 is the JODConverter directory created in Step 1
(If JODConverter has another version number, update convert.bat accordingly)
IMPORTANT: convert.bat file must be located in D2 directory !
Step 4:
Run convert.bat
For each *.doc file present in D2 JODConverter will require Open Office to create a new file with the same name and pdf extension in the same directory.
0
If the Word docs are simple and if you do not need the Word docs' formatting to be present in the PDF docs, you can use a simple loop around my DOCXtoPDF programs's core code, to do what you want. DOCXtoPDF internally uses xtopdf, my Python toolkit for PDF creation from many other formats. You also need ReportLab 1.21 installed.
See:
http://jugad2.blogspot.in/2013/10/convert-microsoft-word-files-to-pdf.html
http://slid.es/vasudevram/xtopdf
If you have also installed LibreOffice then: https://askubuntu.com/a/113802/490067
– Ablaze – 2018-07-20T01:39:16.130