You can read all the details at: Convert PostScript EPS/PS to PNG or JPG Image in C#
Last active
July 4, 2024 03:21
-
-
Save aspose-com-gists/83de7b92a77c31e6ae7d610f4898e010 to your computer and use it in GitHub Desktop.
C# Convert PostScript EPS/PS to PNG or JPG Image Programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PSDocument from PostScript file | |
PsDocument document = new PsDocument("input.ps"); | |
// 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, ImageFormat.Jpeg); | |
//Save PS to JPEG images bytes. | |
// For every page an image bytes array will be obtained where number of byte arrays equals to the number of pages | |
// in input PS file. | |
byte[][] imagesBytes = document.SaveAsImage(options); | |
int i = 0; | |
foreach (byte[] imageBytes in imagesBytes) | |
{ | |
string imagePath = Path.GetFullPath("image" + i.ToString() + "." + imageFormat.ToString()); | |
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write)) | |
{ | |
fs.Write(imageBytes, 0, imageBytes.Length); | |
} | |
i++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize PSDocument from PostScript file | |
PsDocument document = new PsDocument("input.ps"); | |
// 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, ImageFormat.Png); | |
//Save PS to PNG images bytes. | |
// For every page an image bytes array will be obtained where number of byte arrays equals to the number of pages | |
// in input PS file. | |
byte[][] imagesBytes = document.SaveAsImage(options); | |
int i = 0; | |
foreach (byte[] imageBytes in imagesBytes) | |
{ | |
string imagePath = Path.GetFullPath("image" + i.ToString() + "." + imageFormat.ToString()); | |
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write)) | |
{ | |
fs.Write(imageBytes, 0, imageBytes.Length); | |
} | |
i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment