One solution is to use the Print function to generate the PDF:
- Press
Ctrl+P
to open the print dialog
- Select "Microsoft Print to PDF" from the list of printers (or any other PDF printer you may have installed)
- Select a paper format that is large enough to contain your whole drawing
- Click the "Print" button
- In the "Save PDF" dialog that opens now, save the file somewhere.
- Use a program like
pdfcrop
(available on the command line if you have LaTeX installed) or Briss (did not test it personally) to remove the white space around your drawing.
You can also script this process with VBA
On my machine, the script below took about 15-20 minutes to execute in a folder with ~350 Visio files.
After using the VBA script shown below to print all Visio files to PDF, you only need to use pdfcrop
to remove the whitespace. Note: On Windows you will need to install ActivePerl
in addition to MikTeX
in order to use pdfcrop
. Don't know if this is also necessary with TeXLive.
An example PowerShell command could be:
Get-ChildItem "*-print.pdf" | Foreach-Object {
pdfcrop $_.FullName
}
Or in bash
:
for f in *-print.pdf; do
pdfcrop "$f" # or pdfcrop "$f" "${f%-print.pdf}.pdf"
done
After this, you will have a filename-print-crop.pdf
for each filename.vsdx
.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Copy this code into the "ThisDocument" module in a new vsdx file.
'' Save the vsdx file into the folder where the documents reside that
'' you want to convert to pdf.
'' Then run the macro "PrintAllDocumentsInCurrentFolder".
'' Then use pdfcrop or a similar tool to remove the white space.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub PrintOpenDocumentToPDF(oDoc As Document, sOutputFileName As String, Optional iPage As Integer = 1)
' First, ensure that the document fits on one page, without rescaling
If oDoc.Pages(iPage).PrintTileCount > 1 Then
oDoc.PaperSize = visPaperSizeA3 ' Try larger paper
DoEvents ' Let Visio calculate the tiling
End If
If oDoc.Pages(iPage).PrintTileCount > 1 Then
' Still doesn't fit... try changing paper orientation
oDoc.PrintLandscape = Not oDoc.PrintLandscape
DoEvents ' Let Visio calculate the tiling
End If
If oDoc.Pages(iPage).PrintTileCount > 1 Then
' If it still doesn't fit, rescale the image to the paper size
oDoc.PrintFitOnPages = True
oDoc.PrintPagesAcross = 1
oDoc.PrintPagesDown = 1
DoEvents ' Let Visio calculate the tiling
End If
oDoc.PrintOut visPrintFromTo, iPage, iPage, , "Microsoft Print to PDF", True, sOutputFileName
End Sub
Public Sub PrintDocumentToPDF(fileName As String, Optional suffix As String = "-print.pdf")
Dim iExtensionIndex As Integer
Dim sOutputFileName As String
Dim oDoc As Document
iExtensionIndex = InStrRev(fileName, ".")
If iExtensionIndex = 0 Then
MsgBox "Error, could not determine the file extension of file '" + fileName + "'", vbExclamation
Exit Sub
End If
sOutputFileName = Left(fileName, iExtensionIndex - 1) + suffix
Set oDoc = Documents.Open(fileName)
If IsNull(oDoc) Then
MsgBox "Error, could open file '" + fileName + "'", vbExclamation
Exit Sub
End If
PrintOpenDocumentToPDF oDoc, sOutputFileName
Dim lAlertResponseOld As Long
lAlertResponseOld = Application.AlertResponse 'Save alert response so we can revert
Application.AlertResponse = 7 'Tell Visio to choose "Don't Save Changes"
oDoc.Close ' Save changes dialog will not be shown
Application.AlertResponse = lAlertResponseOld 'Revert back to original setting
End Sub
Public Sub PrintAllDocumentsInCurrentFolder()
Dim sFolderName, sThisDocumentName As String
Dim isThisFile, isVsdFile As Boolean
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim iExtensionPos
Dim oPrinter As Object
sFolderName = ThisDocument.Path
sThisDocumentFileName = sFolderName + ThisDocument.Name
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sFolderName)
For Each oFile In oFolder.Files
isThisFile = StrComp(oFile.Path, sThisDocumentFileName) = 0
isVsdFile = InStrRev(oFile.Name, ".vsd") > 0
If isVsdFile And Not isThisFile Then
PrintDocumentToPDF oFile.Path
End If
Next oFile
End Sub