5

I've programatically made a bunch of Excel sheets with xlwt in python. It's all gone fine, but now I need to convert them all to pdf. I've been trying to do this with pywin32 and the com interface. I can get somewhat close by going like this:

import win32com.client
o = win32com.client.Dispatch("Excel.Application")
o.Visible = 1
wb = o.Workbooks.Open('foo.xls')
ws = wb.Worksheets[1]
ws.printout()

But unfortunately when I do this it pops up the adobe printer screen asking me for the path I want to save the pdf to, and if I have to enter that in or click ok for every page it defeats the purpose of doing it programatically. Is there any way I can enter this path in the python code rather than manually? Is there a better way of converting each of these sheets in each of these workbooks to pdf? Thanks a lot, Alex

2
  • 1
    Unfortunately that's the default behavior of the Adobe PDF printer driver. Commented Feb 1, 2012 at 2:01
  • I found that the PrintOut() is case sensitive. Commented Nov 4, 2013 at 13:21

2 Answers 2

4

Instead of using the PrintOut method, use ExportAsFixedFormat. You can specify the pdf format and supply a file name. Try this:

ws.ExportAsFixedFormat(0, 'c:\users\alex\foo.pdf')
Sign up to request clarification or add additional context in comments.

Comments

0

You can do a save as PDF or print to PDF. That should bypass your print driver issues.

1 Comment

hmm ok, sorry how do I do that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.