Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert SVG Image to HTML Webpage Programmatically in C#
// Initialize MemoryStream to save intermediary PDF file
MemoryStream stream = new MemoryStream();
// Load input SVG file
using (SVGDocument document = new SVGDocument("Sample.svg"))
{
// Specify PdfRenderingOptions
PdfRenderingOptions options = new PdfRenderingOptions()
{
// Set Page Setup properties
PageSetup =
{
Sizing = SizingType.FitContent
}
};
using (PdfDevice device = new PdfDevice(options, stream))
{
// Render SVG to PDF file
document.RenderTo(device);
}
}
// Load the PDF document
Document pdfDocument = new Document(stream);
// Save SVG file contents to output HTML format
pdfDocument.Save("Sample.html", SaveFormat.Html);
// Initialize MemoryStream to save intermediary PDF file
MemoryStream stream = new MemoryStream();
// Load input SVG file
using (SVGDocument document = new SVGDocument("Sample.svg"))
// Initialize PdfDevice class object
using (PdfDevice device = new PdfDevice(options, stream))
{
// Render SVG to PDF file
document.RenderTo(device);
}
// Specify PdfRenderingOptions
PdfRenderingOptions options = new PdfRenderingOptions()
{
// Set Page Setup properties
PageSetup =
{
Sizing = SizingType.FitContent
}
};
// Load the rendered PDF document
Document pdfDocument = new Document(stream);
// Save SVG file contents to output HTML format
pdfDocument.Save("Sample.html", SaveFormat.Html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment