Convert XML to PDF in C#, VB.NET

A lot of reasons can be attributed to the common requirement of Office OpenXML to PDF conversion. Office OpenXML(Extensible Markup Language),is a document format that is both human-readable and machine-readable. Even it emphasizes simplicity, generality, and usability over the internet, it is not as conveniently applied, widely supported and safely managed as PDF document format. So this article introduces a solution of three lines of key code to quickly convert Office OpenXML to PDF.

Spire.Doc for .NET is a professional Word component for .NET, which allows users to realize the task of Office OpenXML to PDF conversion through three lines of key code. The first line is for you to load your Office OpenXML file from system by calling Spire.Doc.Document class instance method LoadFromFile; the second is to save the Office OpenXML file as Doc file format by invoking the method SaveToFile to pass a parameter FileFormat.Doc; with the last line, you can save your Doc as PDF file format by the same method SaveToFile to pass the other parameter FileFormat.PDF.

Please Download Spire.Doc for .NET and view the effective screenshot of converting Office OpenXML to PDF below first.


Code sample of  converting Office OpenXML to PDF

using Spire.Doc;

namespace XML2PDf
    class Program
        static void Main(string[] args)
            Document mydoc = new Document();
            mydoc.LoadFromFile(@"..\sample.xml", FileFormat.Xml);
            mydoc.SaveToFile("Test.doc", FileFormat.Doc);
            mydoc.SaveToFile("test.pdf", FileFormat.PDF);

Imports Spire.Doc
Namespace XMLPDf
	Class Program
		Private Shared Sub Main(args As String())
			Dim mydoc As New Document()
			mydoc.LoadFromFile("..\sample.xml", FileFormat.Xml)
			mydoc.SaveToFile("Test.doc", FileFormat.Doc)
			mydoc.SaveToFile("test.pdf", FileFormat.PDF)

		End Sub
	End Class
End Namespace

Besides converting Office OpenXML to PDF, Spire.Doc also can convert Word to PDF, RTF to PDF, Word to Image/EPUB/HTML/Text/Office OpenXML/RTF/Tiff as well as convert HTML to Word/Image, RTF to HTML and Office OpenXML to Word. Click to know more about this Word .NET Component.