how can i print/generate the result in pdf using c#


  • i have this code, i want to implement it to and call a button function so that when you click on it, it will generate a PDF with the result of that id.

    this is my code. I'm open for any help and ideas 

    thanks in advance

    using System;
    using System.Linq;
    using System.Xml;
    using System.Xml.Linq;
    public class Program
    public static void Main()
        string str = @"<?xml version='1.0'?>
                        <date>2011-01-15 12:21:25</date>
                        <date>2011-01-20 10:21:25</date>
        var str1 = XElement.Parse(str);
        //Search ID
        string searchID = "01";
        //Get Result
        var result = str1.Elements("details").Where(x => x.Element("id").Value.Equals(searchID)).ToList();
        if(result.Count() > 0)
            //Get Specific element value
            string s = result[0].Elements("empname").FirstOrDefault().Value;           

    Wednesday, April 19, 2017 2:50 PM

All replies

  • .NET does not provide support for generating PDFs. You'll need to look at a third party library. We cannot provide support for third party libraries but iTextSharp is really popular so you should look into it.

    For further questions related to web development please post in the ASP.NET forums.

    Michael Taylor

    Wednesday, April 19, 2017 6:05 PM
  • Hi tandoh,

    You can take a look at Free Spire.PDF, it's a Free .NET PDF library that supports rich pdf manipulations. You can get the tutorials on the official website to get accustomed to using it.

    • Edited by Shawn Sh Thursday, April 20, 2017 1:17 AM
    Thursday, April 20, 2017 1:16 AM