Convert Word Files into PDFs without using Word Application Scope

I need to convert around 10k word files into pdfs. Currently I’m using “save document as pdf” activity. As the number of word files to convert is around 10k, the time taken to open word files using word application scope is too much. Is there a way to do the process faster?

1 Like

Hi @DarDarSara

Try using this

Dim MyApp As New Microsoft.Office.Interop.Word.Application    
MyApp.Visible = False
Dim MyDoc As Microsoft.Office.Interop.Word.Document = MyApp.Documents.Open(InputFile.ToString)
Mydoc.SaveAs(OutputFile.ToString, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF)
Mydoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges)
MyApp.Quit()

If you have all the word docs in Same folder and the destination filename is same as source filename then you can use this by providing the folder path

Dim MyApp As New Microsoft.Office.Interop.Word.Application    
MyApp.Visible = False
Dim doc As String
Console.WriteLine("Started")
For Each doc In System.IO.Directory.GetFiles(InputFolder,"*.docx")
	console.WriteLine(doc)
	Dim MyDoc As Microsoft.Office.Interop.Word.Document = MyApp.Documents.Open(doc.ToString)
	Mydoc.SaveAs(doc.Replace(".docx",".pdf"), Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF)
	Mydoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges)
Next
Console.WriteLine("Ended")
MyApp.Quit()

You can remove Console.Writeline… Kept them for debugging

cheers

2 Likes

thanks a lot for your solution. It works perfectly fine.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.