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

    Question

  • i have this code, i want to implement it to asp.net 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'?>
                        <information>
                        <details>
                        <id>01</id>
                        <empname>qwer</empname>
                        <empid>001</empid>
                        <dept>Accounts</dept>
                        <date>2011-01-15 12:21:25</date>
                        </details>
                        <details>
                        <id>02</id>
                        <empname>jdfklgd</empname>
                        <empid>002</empid>
                        <dept>Finance</dept>
                        <date>2011-01-20 10:21:25</date>
                        </details>
                        </information>";
    
        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;           
            Console.WriteLine(s);
        }
    }
    }

     
    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
    http://www.michaeltaylorp3.net

    Wednesday, April 19, 2017 6:05 PM
    Moderator
  • 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