Articles in this section
Category / Section

How to Convert SVG to PDF Using C# and VB.NET in ASP.NET Core?

3 mins read

The Syncfusion Essential® PDF is a feature-rich and high performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This guide provides a comprehensive approach to converting SVG files to PDFs using both C# and VB.NET.

Steps to convert SVG to PDF programmatically:

  1. Create a New Project: Start a new Console application in .NET Core to facilitate the HTML-to-PDF conversion process.
    Screenshot (1337).png
  2. Install Required Packages: Add the Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package from Nuget.org to your project.
    HTMLtoPDFWindows.png
  3. Set Up Your Environment: In the Program.cs file, include these namespaces.
    C#
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;

VB.NET

Imports Syncfusion.HtmlConverter
Imports Syncfusion.Pdf
  1. Implement Conversion Logic: Use the following code example in Program.cs to convert SVG files into PDF documents:
    C#
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
string url = Path.GetFullPath(@"Sample.svg");
//Convert a SVG file to PDF with HTML converter
PdfDocument document = htmlConverter.Convert(url);
//Save the PDF document
// Save the document to a memory stream
MemoryStream stream = new MemoryStream();
document.Save(stream);
// Close the document and release all resources
document.Close(true);
// Write the contents of the memory stream to a file
File.WriteAllBytes("SvgToPDF.pdf", stream.ToArray());

VB.NET

' Initialize HTML to PDF converter
Dim htmlConverter As New HtmlToPdfConverter()
' Get the full path of the SVG file
Dim url As String = Path.GetFullPath("Sample.svg")
' Convert the SVG file to a PDF document using the HTML converter
Dim document As PdfDocument = htmlConverter.Convert(url)
' Create a memory stream to save the PDF document
Dim stream As New MemoryStream()
' Save the PDF document to the memory stream
document.Save(stream)
' Close the PDF document and release all resources
document.Close(True)
' Write the contents of the memory stream to a PDF file
File.WriteAllBytes("SvgToPDF.pdf", stream.ToArray()) 

A complete working sample can be downloaded from SVG_To_PDF.zip

By executing the program, the output PDF document will be generated as shown below.Output.png

Take a moment to peruse the documentation, where you will find other options like Html string to PDF, partial webpage to PDF, Html to single PDF page and Html to PDF conversion using IE Rendering with code examples.

Conclusion
I hope you enjoyed learning on how to convert SVG to PDF using C# and VB.NET in ASP.NET Core.
You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page.
If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied