Hi Team,
We have millions of XML documents lacking embedded stylesheets. Our goal is to render these documents as PDFs in a readable format. Currently, rendering these XML files displays the raw XML tags. Could you suggest a solution to render these XML files without stylesheets into a readable format for PDF output, perhaps applying a default styling?
Thanks,
Jyothika
@Jyothika_K,
What Aspose API are you utilizing for XML to PDF conversion? Additionally, could you provide the code snippet that you are currently using? Furthermore, please zip and share a sample XML file and the desired output PDF for our reference. We will review and provide assistance accordingly.
We are using Aspose.Total nuget package
Code snippet : We send the file as bytes and convert it into PDF using Aspose.Words
var doc = new Aspose.Words.Document(ms);
doc.Save(convertedstring, Aspose.Words.SaveFormat.Pdf);
FileContent = convertedstring.ToArray();
I’m attaching a sample xml file here, we have many types of file which do not have same XML tags as in this sample, so a single stylesheet won’t help. We may want a dynamic style to append the details in aligned format .
SampleAsposeXML.zip (851 Bytes)
@Jyothika_K,
I am moving your thread to the respective forum where one of our colleagues from the Aspose.Words team will evaluate your issue and assist you soon.
@Jyothika_K We will check your document and get back to you.
@Jyothika_K This document is a custom XML markup which is not supported by MS Word. By default your file reads as text, because it have no any Word markup. To work with this schema and data you need to use StructuredDocumentTag and CustomXmlPart. You can create template manually with this schema using “Developer” → “XML Mapping Pane” and then pass your data to the custom xml markup:
Document doc = new Document("template.docx");
doc.CustomXmlParts[0].Data = File.ReadAllBytes("SampleAsposeXML.xml");
doc.Save("output.docx");
Or you can try to create such template using Aspose.Words. For example:
Document doc = new Document();
// Construct an XML part that contains text and add it to the document's CustomXmlPart collection.
string xmlPartContent = File.ReadAllText("SampleAsposeXML.xml");
CustomXmlPart xmlPart = doc.CustomXmlParts.Add(Guid.NewGuid().ToString("B"), xmlPartContent);
// Create a structured document tag that will display the contents of our CustomXmlPart.
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Inline);
// Set a mapping for our structured document tag. This mapping will instruct
// our structured document tag to display a portion of the XML part's text contents that the XPath points to.
tag.XmlMapping.SetMapping(xmlPart, "/labresult[1]/labheader[1]/@labcompanyname", string.Empty);
// Add the structured document tag to the document to display the content from our custom part.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Company name: ");
builder.InsertNode(tag);
doc.Save("StructuredDocumentTag.XmlMapping.docx");
In any case, to display this data correctly, you need to create template which will use your data.
Please check more information in our documentation.