Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created February 10, 2021 21:27
Show Gist options
  • Save aspose-com-gists/d58bf88bb1bca6af7affe9383e3a015b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/d58bf88bb1bca6af7affe9383e3a015b to your computer and use it in GitHub Desktop.
Load, Save or Merge SVG Images to PDF XPS JPG PNG Programmatically in C#
// Specify the file path to input SVG
string document = Path.Combine(dataDir, "QBezier.svg");
// OR specify the URL to load the SVG image
var documentUrl = new Url("https://docs.aspose.com/svg/net/drawing-basics/svg-path-data/owl.svg");
// Load an SVG document from a file or URL
var document = new SVGDocument(document)
// Initialize SVG documents from files to merge later
using (var document1 = new SVGDocument(Path.Combine(DataDir, "owl.svg")))
using (var document2 = new SVGDocument(Path.Combine(DataDir, "conclusion.svg")))
using (var document3 = new SVGDocument(Path.Combine(DataDir, "Lineto.svg")))
{
// Create an instance of SvgRenderer
using (var renderer = new SvgRenderer())
{
// Create an instance of PdfDevice
using (var device = new PdfDevice(Path.Combine(OutputDir, "result.pdf")))
{
// Merge all SVG documents to PDF
renderer.Render(device, document1, document2, document3);
}
}
}
// Set a full (complete) path for SVG document saving
var url = new Url(Path.Combine(OutputDir, "Lineto_out.svg"), Directory.GetCurrentDirectory());
// Save SVG to a file
document.Save(documentPath);
// OR Save SVG to the Url
document.Save(url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment