Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 20, 2019 21:28
Show Gist options
  • Select an option

  • Save aspose-com-gists/dd6f6d8ca1153add3a5c80c45467da5a to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/dd6f6d8ca1153add3a5c80c45467da5a to your computer and use it in GitHub Desktop.
Aspose.EPS for .NET
Gist for Aspose.EPS for .NET
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_GettingStarted();
// Initialize license object
Aspose.EPS.License license = new Aspose.EPS.License();
// Set license
license.SetLicense("Aspose.EPS.lic");
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_GettingStarted();
// Initialize license object
Aspose.EPS.License license = new Aspose.EPS.License();
// Load license in FileStream
FileStream myStream = new FileStream("Aspose.EPS.lic", FileMode.Open);
// Set license
license.SetLicense(myStream);
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
using (Stream zip = new SecureLicense().GetType().Assembly.GetManifestResourceStream("Aspose.Total.lic.zip"))
{
using (ZipFile zf = ZipFile.Read(zip))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zf["Aspose.Total.lic"];
e.ExtractWithPassword(ms, "test");
ms.Position = 0;
}
}
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_GettingStarted();
// Initialize license object
Aspose.EPS.License license = new Aspose.EPS.License();
// Set license
license.SetLicense("MergedAPI.Aspose.Total.lic");
// Set the value to indicate that license will be embedded in the application
license.Embedded = true;
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithConverters();
// 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);
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
// Initialize options object with necessary parameters. Default image format is PNG and it is not required to set it in Ps2ApsConverterOptions.
Ps2ApsConverterOptions options = new Ps2ApsConverterOptions(psStream, suppressErrors);
// If you want to obtain images in another format, uncomment following lines
//imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
//options = new Ps2ApsConverterOptions(psStream, suppressErrors, imageFormat);
// Set page size. This size will be also the size of resulting images.
options.PageSize = new System.Drawing.Size(595, 842);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
//options.FontsFolders = new string[] { @"{FONT_FOLDER}" };
Ps2ApsConverter converter = new Ps2ApsConverter();
try
{
// Because PS file can contain several pages for every page an image bytes array will be obtained. //The number of bytes arrays equals to the numberof pages in input PS file.
byte[][] imagesBytes = converter.ConvertToImages(options);
int i = 0;
foreach (byte[] imageBytes in imagesBytes)
{
string imagePath = Path.GetFullPath("image" + i.ToString() + "_out." + imageFormat.ToString().ToLower());
using (FileStream fs = new FileStream(imagePath, FileMode.Create, FileAccess.Write))
{
fs.Write(imageBytes, 0, imageBytes.Length);
}
i++;
}
}
finally
{
psStream.Close();
}
// Review errors
if (suppressErrors)
{
foreach (PsConverterException ex in options.Exceptions)
{
Console.WriteLine(ex.Message);
}
}
// For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithConverters();
// 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);
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
Ps2PdfConverterOptions options = new Ps2PdfConverterOptions(psStream, pdfStream, suppressErrors);
// Set page size
options.PageSize = new System.Drawing.Size(595, 842);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.FontsFolders = new string[] { @"{FONT_FOLDER}" };
try
{
Ps2PdfConverter converter = new Ps2PdfConverter();
converter.ConvertToPdf(options);
}
finally
{
psStream.Close();
pdfStream.Close();
}
// Review errors
if (suppressErrors)
{
foreach (PsConverterException ex in options.Exceptions)
{
Console.WriteLine(ex.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment