问题
I'm trying to convert a bunch of Visio files to pdf in python. I have referenced this .doc to pdf using python and written the following code:
import comtypes.client as coms
format=17
visio = coms.CreateObject('Visio.Application')
doc = visio.Documents.Open('map.vsd')
doc.SaveAs('map.pdf', FileFormat=format)
gives me a TypeError: call takes exactly 2 arguments (3 given)
I've been Googling and can't find the reference on how to print to pdf in Visio using python.
回答1:
You should use ExportAsFixedFormat
instead SaveAs
. Documentation for this function you can find here. This function can be used with a win32 and a comtypes.
win32com example
import win32com.client
visio = win32com.client.Dispatch("Visio.Application")
doc = visio.Documents.Open('map.vsd')
doc.ExportAsFixedFormat( 1, 'map.pdf', 1, 0 )
comtypes example
import comtypes.client as coms
visio = coms.CreateObject('Visio.Application')
doc = visio.Documents.Open('map.vsd')
doc.ExportAsFixedFormat( 1, 'map.pdf', 1, 0 )
来源:https://stackoverflow.com/questions/23534073/python-visio-to-pdf