Upload
Maximum file size: 1 MB. Files accepted: ppt , pptx.
Click here to browse files.
fileerrors
Convert to
Source file:
filename
Target file type:
- Demo
- Java
- C# source
This demo shows you how to convert a PowerPoint document (ppt/pptx) to PDF, HTML, Image, XPS and Tiff.
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; } } }
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++; } } } }
No Matter How Big or Small Your Project is,
Any technical question related to our product, contact us at support@e-iceblue.com.
Any question related to the purchase of product, contact us at sales@e-iceblue.com.
If you don't find the function you want, please request a free demo from us.