public static void Run() { string outputFolder = Constants.GetOutputDirectoryPath(); string outputFileTemplate = Path.Combine(outputFolder, "converted-page-{0}.png"); GroupDocs.Conversion.Contracts.SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create); // Load the source PPT file using (Converter converter = new GroupDocs.Conversion.Converter(Constants.SAMPLE_PPT)) { // Set the convert options for PNG format ImageConvertOptions options = new ImageConvertOptions { Format = GroupDocs.Conversion.FileTypes.ImageFileType.Png }; // Convert to PNG format converter.Convert(getPageStream, options); } Console.WriteLine("\nConversion to png completed successfully. \nCheck output in {0}", outputFolder); }
private static ConvertOptions GetConvertOptions(string destDocumentType, string destinationType) { ConvertOptions convertOptions; switch (destDocumentType) { case "Portable Document Format": convertOptions = new PdfConvertOptions(); break; case "Microsoft Word": convertOptions = new WordProcessingConvertOptions(); break; case "Microsoft PowerPoint": convertOptions = new PresentationConvertOptions(); break; case "image": convertOptions = new ImageConvertOptions(); break; case "Comma-Separated Values": convertOptions = new SpreadsheetConvertOptions(); break; case "Microsoft Excel": convertOptions = new SpreadsheetConvertOptions(); break; default: convertOptions = new WordProcessingConvertOptions(); break; } convertOptions.Format = FileType.FromExtension(destinationType); return(convertOptions); }
private IDataResult <string> Convert(string url, string donusturulecekTur, string uniqueString) { donusturulecekTur = donusturulecekTur.ToLower(); using (Converter converter = new Converter(url)) { if (donusturulecekTur == ImageFileType.Gif.ToString()) { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Gif }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".gif", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".gif", Messages.Convert)); } else if (donusturulecekTur == ImageFileType.Jp2.ToString().ToLower()) { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Jp2 }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".jp2", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + "a.jp2", Messages.Convert)); } else if (donusturulecekTur == "jpg") { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Jpeg }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".jpg", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".jpg", Messages.Convert)); } else if (donusturulecekTur == "jpeg") { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Jpeg }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".jpeg", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".jpeg", Messages.Convert)); } else if (donusturulecekTur == ImageFileType.Png.ToString().ToLower()) { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Png }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".png", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".png", Messages.Convert)); } else if (donusturulecekTur == ImageFileType.Tiff.ToString().ToLower()) { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Tiff }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".tiff", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".tiff", Messages.Convert)); } else if (donusturulecekTur == ImageFileType.Webp.ToString().ToLower()) { ImageConvertOptions options = new ImageConvertOptions { Format = ImageFileType.Webp }; converter.Convert(@"wwwroot/converted/" + uniqueString + ".webp", options); System.IO.File.Delete(url); return(new SuccessDataResult <string>(Server + "converted/" + uniqueString + ".webp", Messages.Convert)); } return(new ErrorDataResult <string>(Messages.NotConvert)); } }