Tab 1
此演示向您展示如何将 PowerPoint 文档 ( ppt/pptx ) 转换为 PDF、HTML、图像、XPS 和 Tiff。
Upload
Maximum file size: 1 MB. Files accepted: ppt , pptx.

fileerrors
Convert to
Source file:
filename
Target file type:
e-iceblue
如果这不是您想要的 Demo,您可以通过填写表格获取免费定制 Demo。
如您有与我们产品相关的其他技术问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。;销售相关的问题,请联系 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。。
Tab 2
package ppt;
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
public class ConvertDemo {
public void convertDemo(String filePath, String convertTo, String resultFileName) throws Exception {
Presentation presentation = new Presentation();
presentation.loadFromFile(filePath);
ConvertFormat(presentation, convertTo,resultFileName);
}
private void ConvertFormat(Presentation presentation, String convertTo, String resultFileName) throws Exception {
switch (convertTo){
case "PDF":
presentation.saveToFile(resultFileName+".pdf", FileFormat.PDF);
break;
case "HTML":
presentation.saveToFile(resultFileName+".html",FileFormat.HTML);
break;
case "IMAGE":
BufferedImage[] images = new BufferedImage[presentation.getSlides().getCount()];
for (int i = 0; i< presentation.getSlides().getCount();i++){
images[i] = presentation.getSlides().get(i).saveAsImage();
}
if (images != null && images.length > 0){
if (images.length == 1){
ImageIO.write(images[0],".PNG", new File(resultFileName+".png"));
}
}else {
for (int j = 0; j < images.length;j++){
String fileName = String.format("image-{0}.png",j);
ImageIO.write(images[j],".PNG",new File(fileName));
}
}
break;
case "XPS":
presentation.saveToFile(resultFileName+".xps",FileFormat.XPS);
break;
case "TIFF":
presentation.saveToFile(resultFileName+".tiff",FileFormat.TIFF);
break;
}
}
}
Tab 3
using Spire.Presentation;
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace DemoOnlineCode
{
class Convertors
{
public void demoConvert(string filePath, string format, string resultFileName)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile(filePath);
ConvertFormat(presentation,format,resultFileName);
}
private static void ConvertFormat(Presentation presentation, string format, string resultFileName)
{
switch (format)
{
case "PDF":
presentation.SaveToFile(resultFileName + ".PDF", FileFormat.PDF);
break;
case "HTML":
presentation.SaveToFile(resultFileName + ".html", FileFormat.Html);
break;
case "IMAGE":
Image[] images = new Image[presentation.Slides.Count];
for (int i = 0; i < presentation.Slides.Count;i++)
{
images[i] = presentation.Slides[i].SaveAsImage();
}
if (images != null && images.Length > 0)
{
if (images.Length == 1)
{
images[0].Save(resultFileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
else
{
for (int i = 0; i < images.Length; i++)
{
string fileName = string.Format("{0}-Image-{1}.png", resultFileName, i);
images[i].Save(fileName, ImageFormat.Png);
}
}
}
break;
case "XPS":
presentation.SaveToFile(resultFileName + ".xps", FileFormat.XPS);
break;
case "TIFF":
Image[] images2 = new Image[presentation.Slides.Count];
if (images2 != null && images2.Length > 0)
{
for (int i = 0; i < presentation.Slides.Count; i++)
{
images2[i] = presentation.Slides[i].SaveAsImage();
}
JoinTiffImages(images2,resultFileName+ ".tiff", EncoderValue.CompressionLZW);
}
break;
}
}
private static ImageCodecInfo GetEncoderInfo(string mimeType)
{
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
for (int j = 0; j < encoders.Length; j++)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
throw new Exception(mimeType + " mime type not found in ImageCodecInfo");
}
public static void JoinTiffImages(Image[] images, string outFile, EncoderValue compressEncoder)
{
//Use the save encoder
System.Drawing.Imaging.Encoder enc = System.Drawing.Imaging.Encoder.SaveFlag;
EncoderParameters ep = new EncoderParameters(2);
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)compressEncoder);
Image pages = null;
int frame = 0;
ImageCodecInfo info = GetEncoderInfo("image/tiff");
foreach (Image img in images)
{
if (frame == 0)
{
pages = img;
//Save the first frame
pages.Save(outFile, info, ep);
}
else
{
//Save the intermediate frames
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
pages.SaveAdd(img, ep);
}
if (frame == images.Length - 1)
{
//Flush and close
ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
pages.SaveAdd(ep);
}
frame++;
}
}
}
}