doc to pdf using python

0 votes
I have a huge number of.doc files to convert to.pdf. And MSWord 2010 is the only program I can use to complete my supervisor's request. I am aware that using Python COM automation, I ought to be able to automate this. The only issue is that I have no idea how or where to begin. I looked online for tutorials, but I couldn't find any (I could have, but I'm not sure what I was looking for).
Sep 24, 2022 in Others by Kithuzzz
• 38,000 points
2,510 views

1 answer to this question.

0 votes

A simple example using comtypes, converting a single file, input and output filenames given as command line arguments:

import sys
import os
import comtypes.client

wdFormatPDF = 17

in_file = os.path.abspath(sys.argv[1])
out_file = os.path.abspath(sys.argv[2])

word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()

You could also use pywin32, which would be the same except for:

import win32com.client

Then:

word = win32com.client.Dispatch('Word.Application')
answered Sep 25, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Python: Convert PDF to DOC

Install LibreOffice and try this: lowriter --invisible --convert-to ...READ MORE

answered Nov 15, 2022 in Others by narikkadan
• 63,600 points
769 views
0 votes
0 answers

How to save Excel sheets to PDF using Python

I have a multiple-sheet Excel spreadsheet. I ...READ MORE

Apr 10, 2023 in Others by Kithuzzz
• 38,000 points
6,025 views
0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
14,024 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
1,345 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How to convert pdf file to excel file using python

Just specify your whole output path instead ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 63,600 points
4,169 views
0 votes
1 answer

How to convert excel to PDF using Python

Specify your whole output path instead of ...READ MORE

answered Nov 10, 2022 in Others by narikkadan
• 63,600 points
3,024 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP