XML to Word and save as PDF

Hi There
I need to convert XML data into a PDF file. I want the end user to be able to influence the design and layout, so my plan is to allow the user to create a Word template, and convert XML data into this.
Simple example XML:
Aspose Inc. Some streetname 23 12334 12 43122 44 56
Information in the tag should be visible in the top of each page.
The tag can appear 0-n times in the XML file. I plan to insert these data into a Word table defined by the user in the Word template file.
Information in the tag should be visible in the bottom of the last page.
After having populated the Word file, I would then save this as a PDF file.
Would this be a good approach?

  • Any issues if the table holding the lines spread over several pages? (if data in a single cell is multi lines, this information must no be divided on different pages)
  • Is it possible to insert data from the tag in the bottom of the last page?

Any suggestions / thoughts are greatly appreciated.

Lost some formatting. The simple example XML file is attached this post.

Hi Bruno,

Thanks for your inquiry.

Yes, you can achieve this using Aspose.Words. You can get data from header or footer tags and insert it inside Word Document’s Header/Footer areas. There are three types of Headers and Footers. For example, if you place header content inside HeaderFirst, it will be visible on the first page only. Regarding the Lines content, you can create Table and insert Row per each Line. The Table can grow to multiple pages but you can decide to allow Row to break across pages:

I hope, this helps.

Best regards,

Sounds great - two additional questions:

  1. Is it possible to have no footer on all pages except the last page?
  2. Can I use “save as” to save the Word document as a PDF file?

Regards
Bruno

Hi Bruno,

Thanks for your inquiry. You can use the following code to make footer content visible only on the last page of document:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// { IF "{PAGE}" = "{NUMPAGES}" "Content Visible on Last Page Only" "" }
Field field = builder.InsertField("IF \"", null);
builder.MoveTo(field.Start.NextSibling.NextSibling);
builder.InsertField("PAGE", null);
builder.Write("\" = \"");
builder.InsertField("NUMPAGES", null);
builder.Write("\" \"Content Visible on Last Page Only\" \"\"");
doc.UpdateFields();
doc.Save(MyDir + @"out.docx");

Secondly yes, you can save any Aspose.Words Document in memory as PDF file. Please refer to the following page:
https://docs.aspose.com/words/net/convert-a-document-to-pdf/

I hope, this helps.

Best regards,