Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 19, 2022 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/ada9064015be0ced399a09c1ec80a267 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/ada9064015be0ced399a09c1ec80a267 to your computer and use it in GitHub Desktop.
Convert SVG to EPS or PS PostScript file Programmatically using C#
// Initialize a MemoryStream object
MemoryStream stream = new MemoryStream();
// Initialize an SVG document from a file
SVGDocument document = new SVGDocument("light.svg");
// Initialize an instance of PdfRenderingOptions class
PdfRenderingOptions pdfRenderingOptions = new PdfRenderingOptions();
pdfRenderingOptions.PageSetup.AnyPage = new Page(new Size(500, 500), new Margin(10, 10, 10, 10));
// Initialize an instance of PdfDevice class
IDevice device = new PdfDevice(pdfRenderingOptions, stream);
// Render SVG to PDF, send the document to the rendering device
document.RenderTo(device);
String printerName = "Microsoft XPS Document Writer";
String psOutFileName = "psOut.ps";
Document pdf = new Document(stream);
// Create the printer settings
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrinterName = (printerName);
printerSettings.PrintToFile = (true);
printerSettings.PrintFileName = (dataDir + psOutFileName);
// Specify page settings
PageSettings pageSettings = new PageSettings();
pageSettings = printerSettings.DefaultPageSettings;
pageSettings.Margins = (new Margins(0, 0, 0, 0));
pageSettings.Color = (true);
PdfViewer viewer = new PdfViewer();
viewer.BindPdf(pdf);
viewer.AutoResize = (true);
viewer.AutoRotate = (true);
viewer.PrintPageDialog = (false);
// Convert the SVG to EPS or PS file
viewer.PrintDocumentWithSettings(pageSettings, printerSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment