Created
August 10, 2023 19:12
-
-
Save conholdate-gists/1f189e34dc76f63305bc3a88f99893a7 to your computer and use it in GitHub Desktop.
Convert SVG to PDF in C# | SVG to PDF Converter in .NET
This file contains hidden or 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
using (var document = new Aspose.Svg.SVGDocument("circle1.svg")) | |
{ | |
// Initialize an instance of the PdfSaveOptions class | |
var saveOptions = new Aspose.Svg.Saving.PdfSaveOptions(); | |
saveOptions.BackgroundColor = System.Drawing.Color.Gray; | |
// Convert SVG to PDF | |
Aspose.Svg.Converters.Converter.ConvertSVG(document, saveOptions, Path.Combine(dataDir, "circle.pdf")); | |
} |
This file contains hidden or 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 an SVG document from a file | |
using (var document = new Aspose.Svg.SVGDocument(Path.Combine(dataDir, "circle.svg"))) | |
{ | |
// Initialize an instance of the PdfRenderingOptions class and set custom PageSetup and JpegQuality properties | |
var pdfRenderingOptions = new Aspose.Svg.Rendering.Pdf.PdfRenderingOptions(); | |
pdfRenderingOptions.PageSetup.AnyPage = new Aspose.Svg.Drawing.Page(new Aspose.Svg.Drawing.Size(500, 500), new Aspose.Svg.Drawing.Margin(10, 10, 10, 10)); | |
pdfRenderingOptions.JpegQuality = 10; | |
// Initialize an instance of the PdfDevice class | |
using (Aspose.Svg.Rendering.IDevice device = new Aspose.Svg.Rendering.Pdf.PdfDevice(pdfRenderingOptions, Path.Combine(dataDir, "out.pdf"))) | |
{ | |
// Render SVG to PDF and send the document to the rendering device | |
document.RenderTo(device); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment