-1
       XmlDocument doc = new XmlDocument();


        string a=textBox1.Text;
        doc.LoadXml(a.Substring(a.IndexOf(Environment.NewLine)));

        XmlWriterSettings settings = new XmlWriterSettings();

        settings.Indent = true;

        XmlWriter writer = XmlWriter.Create("data.xml", settings);
        doc.Save(writer);

In the above code converts textbox content to xml file.Now I required to process each element of the xmlDocument object(doc) and need to create pdf.

string in my textbox is like

Hello

and my Xml file data.xml is saved in debug folder of the project now my pdf should contain a table with one row and one cell which contains "Hello" in it. Could Any one help me to do this.I am very New to programming.

Sowjanya
  • 19
  • 7
  • You're going to have to try to solve the problem yourself, there are tons of resources you can find by just googling a bit (ie. https://stackoverflow.com/a/2937805/292411). If you run into a _specific_ issue you can ask a question here. – C.Evenhuis Jul 05 '17 at 09:58

1 Answers1

0

This is a rather vague question, I don't know what kind of content the "data.xml" can have and how it should be mapped to a PDF file.
You mentioned "Hello" as an example, but that cannot be loaded as XmlDocument...

Nevertheless, here is a small sample that will hopefully get you started (for creating a PDF file I used GemBox.Document):

string a = @"
<table>
  <row>
    <cell>Hello 1-1</cell>
    <cell>Hello 1-2</cell>
  </row>
  <row>
    <cell>Hello 2-1</cell>
    <cell>Hello 2-2</cell>
  </row>
</table>";

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(a.Substring(a.IndexOf(Environment.NewLine)));

XmlWriterSettings settings = new XmlWriterSettings() {  Indent = true };
XmlWriter writer = XmlWriter.Create("data.xml", settings);
xmlDocument.Save(writer);

ComponentInfo.SetLicense("FREE-LIMITED-KEY");
DocumentModel pdfDocument = new DocumentModel();

Table table = new Table(pdfDocument);
table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
pdfDocument.Sections.Add(new Section(pdfDocument, table));

foreach (XmlNode xmlRow in xmlDocument.SelectNodes("/table/row"))
{
    TableRow row = new TableRow(pdfDocument);
    table.Rows.Add(row);

    foreach (XmlNode xmlCell in xmlRow.SelectNodes(".//cell"))
        row.Cells.Add(
            new TableCell(pdfDocument,
                new Paragraph(pdfDocument, xmlCell.InnerText)));
}

pdfDocument.Save("sample.pdf");

Also here is the resulting "sample.pdf": generated sample.pdf file

Mario Z
  • 4,328
  • 2
  • 24
  • 38