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

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>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 姓名:于川皓 学号:16140210089 转载自:https://baike.baidu.com/item/sq...
    道无涯_cc76阅读 1,980评论 0 2
  • Getting Started Use the Current Stable Version (7.1) Buil...
    Leonzai阅读 1,978评论 0 3
  • MP4Box is a MP4 multiplexer. It can import MPEG-4 video, ...
    Goning阅读 4,516评论 0 1
  • '操作文本文件,操作fso对象(文件对象操作) ---------------------------------...
    中華田園雞阅读 437评论 0 1
  • 《鬼谷子的局》以小说的形式,向我们讲述了战国的一段历史,以纵横为主。其中涌现了许多优秀的人物,鬼谷子更被称为,谋略...
    南柯一梦nkym阅读 2,719评论 1 1