Skip to content

Instantly share code, notes, and snippets.

How to Convert XML to PDF in C#. For more information, please follow link: https://kb.conholdate.com/total/java/how-to-convert-xml-to-pdf-in-csharp
using System;
using GroupDocs.Conversion.Options.Convert;
namespace ConvertXmlToPdfInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to convert XML to PDF using C#
{
// Remove the watermark in output PDF document by adding license
string licensePath = "/path/to/GroupDocs.Conversion.lic";
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(licensePath);
// Load the source XML file for conversion to PDF
var converter = new GroupDocs.Conversion.Converter("/path/to/sample.xml");
// Set the convert options for PDF document
var convertOptions = new PdfConvertOptions()
{
Height = 500,
Width = 500,
Dpi = 100,
PageNumber = 1,
PagesCount = 1
};
// Convert and save the XML in PDF format
converter.Convert("/path/to/converted.pdf", convertOptions);
Console.WriteLine("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment