Convert Microsoft Visio Drawing (vsd) to PDF automatically

The open source project I'm working on uses Visio drawings for documentation that are validated in the source control. For those who are working on a project that does not own Visio, we convert vsd files to PDF files so that they can view them. It is not so difficult to save a copy in PDF format when making changes to the documentation, but we would like an automated way to do this conversion so that we can configure it as a preliminary script check in the SVN client. If anyone knows a way to do this, either using something built into Visio, or using an external script or command line tool, we will be grateful.

Edit: Thanks to the suggestion below, I found Visio Viewer 2010 . This will be useful for our authors using Windows. We would still like to be able to create PDF files, although there are readers available in every major operating system, and our authors will not use only Windows.

+6
automation visio
source share
3 answers

I found this nice vbs script and adapted it to visio.It can be called via cygwin (works for all kinds of Office materials)

Option Explicit Main() Sub Main() If WScript.Arguments.Count > 0 Then Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject") Dim i For i = 0 to wscript.arguments.count - 1 Dim strFilePath : strFilePath = WScript.Arguments.Item(i) Dim dirPath : dirPath = objFSO.GetParentFolderName(strFilePath) Dim fileBaseName : fileBaseName = objFSO.GetBaseName(strFilePath) 'WScript.Echo strFilePath Dim strNewFileName : strNewFileName = dirPath & "\" & fileBaseName & ".pdf" 'WScript.Echo strNewFileName Dim strFileExt : strFileExt = UCase(objFSO.GetExtensionName(strFilePath)) Select Case strFileExt Case "DOC" DOC2PDF strFilePath, strNewFileName Case "XLS" XLS2PDF strFilePath, strNewFileName Case "PPT" PPT2PDF strFilePath, strNewFileName Case "VSD" VSD2PDF strFilePath, strNewFileName Case Else WScript.Echo "Extension Type: " & strFileExt End Select Next Else msgbox("Sie muessen eine Datei zum konvertieren auswรคhlen.") End If End Sub Sub PPT2PDF(strSourceFile, strDestFile) Const ppWindowMinimized = 2 Const ppWindowNormal = 1 Const ppSaveAsPDF = 32 Dim objPPT : Set objPPT = CreateObject("PowerPoint.Application") objPPT.Visible = True objPPT.WindowState = ppWindowMinimized objPPT.Presentations.Open strSourceFile objPPT.ActivePresentation.SaveAs strDestFile, ppSaveAsPDF objPPT.Quit() End Sub Sub DOC2PDF(strSourceFile, strDestFile) Const wdExportAllDocument = 0 Const wdExportOptimizeForPrint = 0 Const wdExportDocumentContent = 0 Const wdExportFormatPDF = 17 Const wdExportCreateHeadingBookmarks = 1 Dim objWord : Set objWord = CreateObject("Word.Application") Dim objDoc : Set objDoc = objWord.Documents.Open(strSourceFile,,TRUE) objWord.ActiveDocument.ExportAsFixedFormat strDestFile, wdExportFormatPDF, False, _ wdExportOptimizeForPrint, wdExportAllDocument,,, _ wdExportDocumentContent, False, True, wdExportCreateHeadingBookmarks objWord.Quit() End Sub Sub XLS2PDF(strSourceFile, strDestFile) Const xlTypePDF = 0 Dim objExcel : Set objExcel = CreateObject("Excel.Application") Dim objeDoc : Set objeDoc = objExcel.Workbooks.Open(strSourceFile,,TRUE) objExcel.ActiveWorkbook.ExportAsFixedFormat xlTypePDF, strDestFile objExcel.ActiveWorkbook.Close(False) objExcel.Quit End Sub Sub VSD2PDF(strSourceFile, strDestFile) Const xlTypePDF = 1 Const visOpenRO = 2 Const visOpenMinimized = 16 Const visOpenHidden = 64 Const visOpenMacrosDisabled = 128 Const visOpenNoWorkspace = 256 Dim objVisio : Set objVisio = CreateObject("Visio.Application") Dim objeDoc : Set objeDoc = objVisio.Documents.OpenEx(strSourceFile, visOpenRO + visOpenMinimized + visOpenHidden + visOpenMacrosDisabled + visOpenNoWorkspace) objeDoc.ExportAsFixedFormat xlTypePDF, strDestFile, 1, 0 objeDoc.Close objVisio.Quit End Sub 
+4
source share

You can use vsd2svg and svg2pdf for the conversion process - if you want to do this on the command line. Or basic libraries.

http://dia-installer.de/vsd2svg

http://cgit.freedesktop.org/~cworth/svg2pdf/

+2
source share

Visio 2007 added the ExportAsFixedFormat method to the Visio API, which allows you to programmatically create a PDF file in Visio.

The tricky part is deploying the code in a way that makes sense for your project. You can create a stencil that just acts as an addon and attach this stencil to all Visio documents in your project. The code in the template will simply watch the Visio application object for DocumentSaved events and save the PDF document in the same folder.

0
source share

All Articles