How to convert doc file into pdf using python

0 votes

Is anyone know how to convert doc file into pdf using python?

Nov 4, 2020 in Python by anonymous
• 10,520 points
1,665 views

1 answer to this question.

0 votes

A simple example using com types, 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

and then:

word = win32com.client.Dispatch('Word.Application')
answered Nov 4, 2020 by Gitika
• 65,910 points

Related Questions In Python

0 votes
1 answer

How to import an image into a csv file using python?

I am sure you are aware CSV ...READ MORE

answered Jun 25, 2020 in Python by Bhanu Kumar
7,304 views
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 58,090 points
1,115 views
0 votes
1 answer

How to download a file over HTTP using Python?

In Python 2, use urllib2 which comes ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,300 points
656 views
0 votes
1 answer

How to convert an integer to a string using Python?

Here is an easy solution: def numberToBase(n, b): ...READ MORE

answered Nov 23, 2018 in Python by Nymeria
• 3,560 points

edited Dec 12, 2018 by Nymeria 785 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,051 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,468 views
0 votes
1 answer
0 votes
2 answers

How do I convert text file to CSV file with only plain python. Meaning no panda or any other special module?

Steps to Convert Text File to CSV ...READ MORE

answered Oct 15, 2020 in Python by Abdul Shekh
8,329 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