美文网首页
用vbs写一个命令行PPT转图片工具

用vbs写一个命令行PPT转图片工具

作者: Flueg | 来源:发表于2018-08-01 19:26 被阅读79次

    Dependence:
    Windows系统,安装有MS Office或者WPS Office
    ppt2imgas.vbs:

    Option Explicit

    Sub WriteLine ( strLine )
    WScript.Stdout.WriteLine strLine
    End Sub

    Dim inputFile
    Dim outputDir
    Dim objPPT
    Dim objPresentation
    Dim objPrintOptions
    Dim objFso

    Dim oSl
    Dim lWidthInPixels
    Dim lHeightInPixels

    If WScript.Arguments.Count <> 2 Then
    WriteLine "You need to specify input and output files."
    WScript.Quit
    End If

    inputFile = WScript.Arguments(0)
    outputDir = WScript.Arguments(1)

    Set objFso = CreateObject("Scripting.FileSystemObject")

    If Not objFso.FileExists( inputFile ) Then
    WriteLine "Unable to find your input file " & inputFile
    WScript.Quit
    End If

    Function CreateFolderRecursive(path)
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")

    'If the path exists as a file, the function fails.
    If FSO.FileExists(path) Then
        CreateFolderRecursive = False
        Exit Function
    End If
    
    'If the path already exists as a folder, don't do anything and return success.
    If FSO.FolderExists(path) Then
        CreateFolderRecursive = True
        Exit Function
    End If
    
    'recursively create the parent folder, then if successful create the top folder.
    If CreateFolderRecursive(FSO.GetParentFolderName(path)) Then
        If FSO.CreateFolder(path) Is Nothing Then
            CreateFolderRecursive = False
        Else
            CreateFolderRecursive = True
        End If
    Else
        CreateFolderRecursive = False
    End If
    

    End Function

    If Not CreateFolderRecursive(outputDir) Then
    WriteLine "Unable to find your output dir " & outputDir
    WScript.Quit
    End If

    WriteLine "Input File: " & inputFile

    On Error Resume Next ' Defer error trapping.
    Set objPPT = Getobject(, "PowerPoint.Application")
    If Err.Number <> 0 Then
    Err.Clear ' Clear Err object in case error occurred.
    Set objPPT = CreateObject("PowerPoint.Application")
    End If

    objPPT.Visible = True
    objPPT.Presentations.Open inputFile

    Set objPresentation = objPPT.Presentations(objFso.GetFileName(inputFile))
    Set objPrintOptions = objPresentation.PrintOptions

    objPrintOptions.Ranges.Add 1,objPresentation.Slides.Count
    objPrintOptions.RangeType = ppShowAll

    lWidthInPixels = 1920
    lHeightInPixels = 1080

    For Each oSl In objPresentation.Slides
    oSl.Export outputDir & "\I_" & oSl.SlideIndex & ".jpg", _
    "JPG", _
    lWidthInPixels, _
    lHeightInPixels
    Next

    objPresentation.Close

    Run CMD:
    cscript ppt2imags.vbs <ppt file path> <output dir>

    相关文章

      网友评论

          本文标题:用vbs写一个命令行PPT转图片工具

          本文链接:https://www.haomeiwen.com/subject/fnorvftx.html