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 in Others by Kithuzzz
• 20,660 points
160 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 by narikkadan
• 37,660 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 in Others by narikkadan
• 37,660 points
27 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 in Others by Edureka
• 13,640 points
6,117 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 in Others by narikkadan
• 37,660 points
116 views
0 votes
1 answer

Print chosen worksheets in excel files to pdf in python

In the simplest form: import win32com.client o = win32com.client.Dispatch("Excel.Application") o.Visible ...READ MORE

answered Sep 24 in Others by narikkadan
• 37,660 points
202 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 3,131 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 in Others by narikkadan
• 37,660 points
153 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 in Others by narikkadan
• 37,660 points
94 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