Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
XML is a great way for enabling data interchange. PDF offers a great way for presenting data.
That brings us to the point of how to take data from XML and present it in PDF. PDFOne .NET provides a very simple method to read XML data and render it in PDF files.
In this article, you will see a project that converts XML data to PDF.
Specifically, PDFOne .NET supports place holders in text strings that are written to PDF documents. Users can define their own place holders and then supply the values from XML through an event.
This project supplies data stored in XML nodes through place holders.
The main method Button1_Click
renders the PDF document.
The GetXmlData
method supplies the value for the place holders.
GetXmlData
gets data through XmlTextReader
in case of Microsoft Visual Studio 2005®.
(Visual Studio 2005 has all the methods necessary for reading values of each node.)
using Gnostice.PDFOne; using System.IO; using System.Xml; // Creates a string containing XML-formatted datastatic string xmlString = "" + " // Creates an xml text reader objct for reading the // xml input data XmlTextReader textReader = new XmlTextReader(new StringReader(xmlString)); private void Button1_Click(object sender, EventArgs e) { PDFDocument doc = new PDFDocument(); // Fills the variables with data (performed // by the delegate under this method) doc.ReplaceVariable += new ReplaceVariableEventHandler(GetXMLData); ... for (i = 0; i < noOfRecords; i++, yLocation += 0.4f) { doc.WriteText("Name", 1, yLocation); // Replaces placeholder <%name%> with value read from // the XML string doc.WriteText("<%name%>", 2, yLocation); yLocation += 0.2f; doc.WriteText("Age", 1, yLocation); // Replaces placeholder <%age%> with value read from // the XML string doc.WriteText("<%age%>", 2, yLocation); yLocation += 0.2f; doc.WriteText("Gender", 1, yLocation); // Replaces placeholder <%gender%> with value read from // the XML string doc.WriteText("<%gender%>", 2, yLocation); } ... } void GetXMLData(object sender, string variable, ref string newValue, ref bool replace) { textReader.ReadToFollowing(variable); newValue = textReader.ReadString(); }" + " ";" + " Rita 23 " + "female " + " Bob 25 " + "male " + " Sam 32 " + "male " + " Julie 20 " + "female
Downloads:
GetData
is used (not shown here but included in this project), which fetches data manually.
---o0O0o---
Our .NET Developer Tools | |
---|---|
Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
Our Delphi/C++Builder developer tools | |
---|---|
Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
Our Java developer tools | |
---|---|
Gnostice Document Studio JavaMulti-format document-processing component suite for Java developers. |
PDFOne (for Java)A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications. |
Our Platform-Agnostic Cloud and On-Premises APIs | |
---|---|
StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved. |