# otherwise settings for the next job may not be used # wait until print job completes before continuing Util.PrintFile(file, util.DefaultPrinterName) # send to Bullzip virtual printer Settings.WriteSettings(True) # write settings to the runonce.ini Settings.SetValue("StatusFile", statusFile) # created after print job Settings.SetValue("ShowProgressFinished", "no") # disable balloon tip Settings.SetValue("ShowSettings", "never") Settings.SetValue("ConfirmOverwrite", "no") Settings.PrinterName = util.DefaultPrinterName # make sure we're controlling the right PDF printer import os, re, time, datetime, win32com.client When printing multiple PDFs we need to make sure one print job completes before starting another to ensure the settings are used correctly for each file. The settings are written to a "runonce" file which is used for one print job only and then removed automatically. The COM API can be found here and a list of the usable settings can be found here. You'll find a "free community edition" on their download page. It's now replaced the other virtual printers I used previously. After looking how to disable the dialogs when using a virtual PDF printer I came across Bullzip PDF Printer and I've been rather impressed with its features. I tried the accepted answer but wasn't particularly keen on the bloated PDFs Word was producing which was usually an order of magnitude bigger than expected. # key point 2: wait for the COM Server to prepare well.ĭoc=(in_file) # open docx file 1ĭoc.SaveAs(out_file, FileFormat=wdFormatPDF) # conversionĭoc = (in_file2) # open docx file 2ĭoc.SaveAs(out_file2, FileFormat=wdFormatPDF) # conversion # key point 1: make word visible before open a new document Out_file2=r'absolute path of outputpdf file 2' In_file2=r'absolute path of input docx file 2' Out_file=r'absolute path of output pdf file 1' In_file=r'absolute path of input docx file 1' # be careful about the slash '\', use '\\' or '/' or raw string r"." If you have encountered the same problems, try to follow these two steps. So I add a delay before I tried to open a document.Īfter doing these two steps, the program will work perfectly with no failure anymore. The crash error "COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))" means that the COM Server may not be able to response so quickly. After doing (1), the program will work well sometimes but may fail often. If I do not do this on my computer, the program will crash when I try to open a document in the invisible model, then the 'Word.Application' object will be deleted by OS. (Actually, even I myself cannot explain why this works. The first time when I created the 'Word.Application' object, I should make it (the word app) visible before open any documents. Steven's answer is right, but it will fail on my computer. I have worked on this problem for half a day, so I think I should share some of my experience on this matter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |