private Response ConvertEpsToImage(string fileName, string folderName, string outputType) { return(ProcessTask(fileName, folderName, "." + outputType, true, false, delegate(string inFilePath, string outPath, string zipOutFolder) { FileStream psStream = new FileStream(inFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Tiff; switch (outputType) { case "bmp": imageFormat = System.Drawing.Imaging.ImageFormat.Bmp; break; case "png": imageFormat = System.Drawing.Imaging.ImageFormat.Png; break; case "jpg": imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; break; } PsDocument document = new PsDocument(psStream); Aspose.Page.EPS.Device.ImageSaveOptions options = new Aspose.Page.EPS.Device.ImageSaveOptions(true); Aspose.Page.EPS.Device.ImageDevice device = new Aspose.Page.EPS.Device.ImageDevice(); //Aspose.Page.EPS.Device.ImageDevice device = new Aspose.Page.EPS.Device.ImageDevice(new System.Drawing.Size(595, 842), imageFormat); try { document.Save(device, options); } finally { psStream.Close(); } byte[][] imagesBytes = device.ImagesBytes; int i = 0; foreach (byte[] imageBytes in imagesBytes) { string imagePath = Path.GetFileNameWithoutExtension(fileName) + "_" + (i + 1) + "." + outputType; outPath = zipOutFolder + "/" + imagePath; using (FileStream fs = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { fs.Write(imageBytes, 0, imageBytes.Length); } i++; } })); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocumentConversion(); // Initialize PDF output stream System.IO.FileStream pdfStream = new System.IO.FileStream(dataDir + "outputPDF_out.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write); // Initialize PostScript input stream System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "input.ps", System.IO.FileMode.Open, System.IO.FileAccess.Read); PsDocument document = new PsDocument(psStream); // If you want to convert Postscript file despite of minor errors set this flag bool suppressErrors = true; //Initialize options object with necessary parameters. PdfSaveOptions options = new PdfSaveOptions(suppressErrors); // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" }; // Default page size is 595x842 and it is not mandatory to set it in PdfDevice Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream); // But if you need to specify size and image format use following line //Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new System.Drawing.Size(595, 842)); try { document.Save(device, options); } finally { psStream.Close(); pdfStream.Close(); } //Review errors if (suppressErrors) { foreach (PsConverterException ex in options.Exceptions) { Console.WriteLine(ex.Message); } } // ExEnd:1 }
///<Summary> /// ConvertEpsToPdf method to convert eps file to pdf ///</Summary> public Response ConvertEpsToPdf(string fileName, string folderName) { return(ProcessTask(fileName, folderName, ".pdf", false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { FileStream psStream = new FileStream(inFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); FileStream pdfStream = new FileStream(outPath, System.IO.FileMode.Create, System.IO.FileAccess.Write); PsDocument document = new PsDocument(psStream); PdfSaveOptions options = new PdfSaveOptions(true); PdfDevice device = new PdfDevice(pdfStream); try { document.Save(device, options); } finally { psStream.Close(); pdfStream.Close(); } })); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocumentConversion(); // Initialize PDF output stream System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Png; // Initialize PostScript input stream System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "inputForImage.ps", System.IO.FileMode.Open, System.IO.FileAccess.Read); PsDocument document = new PsDocument(psStream); // If you want to convert Postscript file despite of minor errors set this flag bool suppressErrors = true; //Initialize options object with necessary parameters. ImageSaveOptions options = new ImageSaveOptions(suppressErrors); // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. options.AdditionalFontsFolders = new string[] { @"{FONT_FOLDER}" }; // Default image format is PNG and it is not mandatory to set it in ImageDevice // Default image size is 595x842 and it is not mandatory to set it in ImageDevice Aspose.Page.EPS.Device.ImageDevice device = new Aspose.Page.EPS.Device.ImageDevice(); // But if you need to specify size and image format use constructor with parameters //ImageDevice device = new ImageDevice(new System.Drawing.Size(595, 842), System.Drawing.Imaging.ImageFormat.Jpeg); try { document.Save(device, options); } finally { psStream.Close(); } byte[][] imagesBytes = device.ImagesBytes; int i = 0; foreach (byte[] imageBytes in imagesBytes) { string imagePath = Path.GetFullPath("out_image" + i.ToString() + "." + imageFormat.ToString().ToLower()); using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write)) { fs.Write(imageBytes, 0, imageBytes.Length); } i++; } //Review errors if (suppressErrors) { foreach (PsConverterException ex in options.Exceptions) { Console.WriteLine(ex.Message); } } // ExEnd:1 }
private List <string> GetDocumentPages(string file, string folderName, int currentPage) { List <string> lstOutput = new List <string>(); string outfileName = "page_{0}"; string outPath = Config.Configuration.OutputDirectory + folderName + "/" + outfileName; currentPage = currentPage - 1; Directory.CreateDirectory(Config.Configuration.OutputDirectory + folderName); string imagePath = string.Format(outPath, currentPage) + ".jpeg"; if (System.IO.File.Exists(imagePath) && currentPage > 0) { lstOutput.Add(imagePath); return(lstOutput); } int i = currentPage; var filename = System.IO.File.Exists(Config.Configuration.WorkingDirectory + folderName + "/" + file) ? Config.Configuration.WorkingDirectory + folderName + "/" + file : Config.Configuration.OutputDirectory + folderName + "/" + file; using (FilePathLock.Use(filename)) { try { if (!System.IO.File.Exists(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf")) { Aspose.Page.Live.Demos.UI.Models.License.SetAsposePageLicense(); System.IO.FileStream pdfStream = new System.IO.FileStream(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf", System.IO.FileMode.CreateNew, System.IO.FileAccess.Write); System.IO.FileStream psStream = new System.IO.FileStream(Config.Configuration.WorkingDirectory + folderName + "/" + file, System.IO.FileMode.Open, System.IO.FileAccess.Read); try { if (file.ToLower().EndsWith(".xps")) { Page.XPS.XpsDocument document = new XpsDocument(psStream, new Page.XPS.XpsLoadOptions()); Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.XPS.Presentation.Pdf.PdfSaveOptions(); Aspose.Page.XPS.Presentation.Pdf.PdfDevice device = new Aspose.Page.XPS.Presentation.Pdf.PdfDevice(pdfStream, new Size(595, 842)); document.Save(device, options); } else { PsDocument document = new PsDocument(psStream); Aspose.Page.EPS.Device.PdfSaveOptions options = new Aspose.Page.EPS.Device.PdfSaveOptions(true); Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new Size(595, 842)); document.Save(device, options); } } finally { psStream.Close(); pdfStream.Close(); } } PdfConverter objConverter = new PdfConverter(); objConverter.BindPdf(Config.Configuration.OutputDirectory + folderName + "/" + "outputPDF.pdf"); objConverter.DoConvert(); objConverter.CoordinateType = PageCoordinateType.CropBox; if (currentPage < objConverter.PageCount) { lstOutput.Add(objConverter.PageCount.ToString()); i = 0; while (objConverter.HasNextImage() && i < objConverter.PageCount) { objConverter.StartPage = (currentPage + 1); objConverter.GetNextImage(imagePath, System.Drawing.Imaging.ImageFormat.Png); lstOutput.Add(imagePath); break; } } objConverter.Close(); } catch (Exception ex) { throw ex; } return(lstOutput); } }