在Windows上将PPT转换为JPG / PNG

用户名

我想在Windows环境中以编程方式在一组图像中转换一个ppt演示文稿,每个幻灯片一个。

我试图修改以下将ppt转换为pdf的代码(可以正常工作),但没有成功。谁能帮我?非常感谢。

Option Explicit

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

' http://msdn.microsoft.com/en-us/library/office/aa432714(v=office.12).aspx
Const msoFalse = 0   ' False.
Const msoTrue = -1   ' True.

' http://msdn.microsoft.com/en-us/library/office/bb265636(v=office.12).aspx
Const ppFixedFormatIntentScreen = 1 ' Intent is to view exported file on screen.
Const ppFixedFormatIntentPrint = 2  ' Intent is to print exported file.

' http://msdn.microsoft.com/en-us/library/office/ff746754.aspx
Const ppFixedFormatTypeXPS = 1  ' XPS format
Const ppFixedFormatTypePDF = 2  ' PDF format

' http://msdn.microsoft.com/en-us/library/office/ff744564.aspx
Const ppPrintHandoutVerticalFirst = 1   ' Slides are ordered vertically, with the first slide in the upper-left corner and the second slide below it.
Const ppPrintHandoutHorizontalFirst = 2 ' Slides are ordered horizontally, with the first slide in the upper-left corner and the second slide to the right of it.

' http://msdn.microsoft.com/en-us/library/office/ff744185.aspx
Const ppPrintOutputSlides = 1               ' Slides
Const ppPrintOutputTwoSlideHandouts = 2     ' Two Slide Handouts
Const ppPrintOutputThreeSlideHandouts = 3   ' Three Slide Handouts
Const ppPrintOutputSixSlideHandouts = 4     ' Six Slide Handouts
Const ppPrintOutputNotesPages = 5           ' Notes Pages
Const ppPrintOutputOutline = 6              ' Outline
Const ppPrintOutputBuildSlides = 7          ' Build Slides
Const ppPrintOutputFourSlideHandouts = 8    ' Four Slide Handouts
Const ppPrintOutputNineSlideHandouts = 9    ' Nine Slide Handouts
Const ppPrintOutputOneSlideHandouts = 10    ' Single Slide Handouts

' http://msdn.microsoft.com/en-us/library/office/ff745585.aspx
Const ppPrintAll = 1            ' Print all slides in the presentation.
Const ppPrintSelection = 2      ' Print a selection of slides.
Const ppPrintCurrent = 3        ' Print the current slide from the presentation.
Const ppPrintSlideRange = 4     ' Print a range of slides.
Const ppPrintNamedSlideShow = 5 ' Print a named slideshow.

' http://msdn.microsoft.com/en-us/library/office/ff744228.aspx
Const ppShowAll = 1             ' Show all.
Const ppShowNamedSlideShow = 3  ' Show named slideshow.
Const ppShowSlideRange = 2      ' Show slide range.

'
' This is the actual script
'

Dim inputFile
Dim outputFile
Dim objPPT
Dim objPresentation
Dim objPrintOptions
Dim objFso

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

inputFile = WScript.Arguments(0)
outputFile = 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

If objFso.FileExists( outputFile ) Then
    WriteLine "Your output file (' & outputFile & ') already exists!"
    WScript.Quit
End If

WriteLine "Input File:  " & inputFile
WriteLine "Output File: " & outputFile

Set objPPT = CreateObject( "PowerPoint.Application" )

objPPT.Visible = True
objPPT.Presentations.Open inputFile

Set objPresentation = objPPT.ActivePresentation
Set objPrintOptions = objPresentation.PrintOptions

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

' Reference for this at http://msdn.microsoft.com/en-us/library/office/ff746080.aspx
objPresentation.ExportAsFixedFormat outputFile, ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputSlides, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False

objPresentation.Close
ObjPPT.Quit
史蒂夫·林兹伯格

不要使用.ExportAsFixedFormat。而是在每个幻灯片上使用.SaveAs或使用.Export方法。

.Export使您拥有更多控制权。在VBA中,您需要这样做:

Dim oSl As Slide
Dim lWidthInPixels As Long
Dim lHeightInPixels As Long

lWidthInPixels = 1024
lHeightInPixels = 768

For Each oSl In ActivePresentation.Slides
    oSl.Export "c:\path\myfile" & Format(oSl.SlideIndex, "0000") & ".jpg", _
        "JPG", _
        lWidthInPixels, _
        lHeightInPixels
Next

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Linux上将pptx文件转换为jpg或png(每个幻灯片)?

来自分类Dev

在Mac上将jpg的文件夹转换为png的脚本时出错

来自分类Dev

在Linux上将.png图像转换成.ppt演示文稿?

来自分类Dev

将webm转换为jpg或png

来自分类Dev

在python中将PNG转换为JPG

来自分类Dev

rmagick压缩并将png转换为jpg

来自分类Dev

将webm转换为jpg或png

来自分类Dev

在Linux中将PNG批量转换为JPG

来自分类Dev

Grunt 将 .png 转换为 .jpg 文件

来自分类Dev

将透明 png 转换为 jpg powershell

来自分类Dev

关于将PNG转换为JPG

来自分类Dev

Android-在Android <4.0上将png资源转换为ColorDrawable

来自分类Dev

在Linux上将SWF文件转换为PNG图像

来自分类Dev

从PNG转换为EPS

来自分类Dev

将HttpPostedFileBase-pdf类型转换为png / jpg类型

来自分类Dev

使用ImageMagick将图像转换为PNG和JPG

来自分类Dev

将PDF的首页转换为JPG或PNG-PHP

来自分类Dev

使用Python将BLOB图像转换为PNG,JPG

来自分类Dev

使用PHP将JPG / PNG转换为SVG格式

来自分类Dev

使用ImageMagick将图像转换为PNG和JPG

来自分类Dev

在Rails中将PDF转换为JPG / PNG错误的尺寸

来自分类Dev

如何将.jpg或.png图像转换为.raw格式?

来自分类Dev

使用终端和后端将.JPG或.PNG转换为.ICO

来自分类Dev

从jpg转换为png并返回数次(质量下降?)

来自分类Dev

PDF转换为黑白PNG

来自分类Dev

将PHP转换为PNG

来自分类Dev

将Xcursor转换为PNG

来自分类Dev

转换〜1000 swf为jpg / png / gif

来自分类Dev

在Mac OS X上将SVG转换为PNG的命令行应用程序