How to convert XML to Pdf

Hi Team,

I am trying to convert a Xml file into Pdf .
I am using using the code metioned here -; Convert PDF documents using C# API|Aspose.PDF for .NET

But the converted Pdf always fail to open, with this mesaage
image.png (8.9 KB)

I am using Aspose.Pdf for .net version - 17.12.0
.Net platform - 4.6
OS - windows server 2012R2

Here is the code snippet -:
image.png (7.9 KB)

The sample input XML I took from here -;
https://msdn.microsoft.com/en-us/library/ms762271(v=vs.85).aspx

Kindly note -: All the XMl’s that I need to convert, I dont have schema for them.

Kindly reply as soon as possible .

Regards
Harshit

@harsh1691,

In order to convert an XML to PDF, you need to understand the internal element hierarchy of the PDF structure. Your source XML file must follow the Aspose.Pdf for .NET schema. Please refer to this help topic: Introduction to the DOM API

Hi Imran ,

Thanks for sharing the article.
As per my understanding the article contains the following information -:

  1. DOM structure of the Aspose Pdf.
    2)and the process for creating Pdf Portfolio.

  2. because we dont have any XML schema, it will be hard to identify which different elements of the xml correspond to which part of the Pdf DOM .

  3. Creating pdf portfolio is entirely a different thing, which we dont require at this point.

Kindly tell any other way to achieve the conversion.

Regards
Harshit

@harsh1691,

In order to convert the sample XML, you can prepare a template of the Word document with merge fields, and then execute mail merge to incorporate XML data, finally save the document into the PDF format. Please refer to this help topic: How to Mail Merge from XML using LINQ to XML