Python Visio to pdf

一世执手 提交于 2020-04-14 06:06:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!