当前位置:网站首页>visio文件批量转pdf

visio文件批量转pdf

2022-08-11 05:33:00 hello_zard

# Convert Visio (2013) documents to PDF 

$drawings = Get-ChildItem -Filter "*.vsdx"
Write-Host "Converting Visio documents to PDF..." -ForegroundColor Cyan

try
{
    $visio = New-Object -ComObject Visio.Application
    $visio.Visible = $true

    foreach ($drawing in $drawings)
    {
        $pdfname = [IO.Path]::ChangeExtension($drawing.FullName, '.pdf')
        Write-Host "Converting:" $drawing.FullName "to" $pdfname
        $document = $visio.Documents.Open($drawing.FullName)
        # Export all pages to PDF, see constants here http://msdn.microsoft.com/en-us/library/office/ff766893.aspx
        $document.ExportAsFixedFormat(1, $pdfname, 1, 0)
    }

}

catch
{
    Write-Error $_
}

finally
{
    if ($visio) 
    {
        $visio.Quit()
    }

}

代码保存未hello.ps1

右键hello.ps1,点击Powershell运行,然后就会读取本目录下全部vsdx后缀的文件,然后程序会自动调用电脑的visio程序打开文档然后转为pdf后就会自动关闭visio文档,转换后的pdf就在当前文件夹下面。

原网站

版权声明
本文为[hello_zard]所创,转载请带上原文链接,感谢
https://blog.csdn.net/A694543965/article/details/125555431