none
create pdf file from C#.net

    Question

  • Hi,

    I need to do the following task in C#.Net. Can anyone tell me which is the best method to follow? Is there any in build features available in .net? Or do we need to use some external libraries.

    * Import grid view data to pdf and save it in local disc (create pdf file in runtime)

    * Read content from pdf file and convert it into grid view

     

    Thanks in advance!

    Regards,

    Sakthivel. S

     

    Thursday, June 24, 2010 8:29 AM

Answers

All replies

    • Marked as answer by SamAgain Friday, July 02, 2010 3:07 AM
    Thursday, June 24, 2010 9:07 AM
    • Marked as answer by SamAgain Friday, July 02, 2010 3:07 AM
    Thursday, June 24, 2010 6:44 PM
  • This external library enables you to create PDF from C# very easily. Just create create document model table populated with data from grid view and export it to PDF.

    Here is a C# code:

    // Create a new empty document.
    DocumentModel document = new DocumentModel();
    
    var table = new Table(document);
    
    // Call method that creates rows and cells with data from GridView and adds them to Table.
    PopulateTable(gridView, table);
    
    // Add document content.
    document.Sections.Add(
    	new Section(document,
    		table));
     
    // Save the document to a PDF file.
    document.Save("Document.pdf");

    Thursday, July 19, 2012 7:54 AM
  • You can use pdfsharp library for generating pdf file from c# applications check this one ..  Create PDF file from C# is explain the simple step by step methods to generate pdf file from c#.

    Liam


    • Edited by liam_web Friday, October 18, 2013 6:04 AM spell
    Friday, October 18, 2013 6:03 AM
  • Creating PDF file in runtime can be done with this tool http://www.componentpro.com/pdf.net/. I paste code snippet to create a PDF document (the code is copied from: http://www.componentpro.com/doc/pdf/Creating-tables.htm)

    using System;
    using System.Drawing;
    using ComponentPro.Pdf;
    using ComponentPro.Pdf.Graphics;
    using ComponentPro.Pdf.Tables;
    
    ...
    
    static string[][] datastring = new string[2][];
    
    [STAThread]
    static void Main()
    {
        // Create a new PDF document. This object represents the PDF document.
        // This document has one page, by default. Additional pages have to be added.
        PdfDocument doc = new PdfDocument();
    
        // Add a page to the document 
        PdfPage page = doc.Pages.Add();
    
        // Specify values for the table
        datastring[0] = new string[] {"111", "Maxim", "100"};
        datastring[1] = new string[] {"222", "Calvin", "95"};
        // Creates a new document
        PdfSimpleTable table = new PdfSimpleTable();
        table.DataSource = datastring;
    
        table.BeforeRowLayout += new BeforeRowLayoutEventHandler(table_BeforeRowLayout);
        table.BeforeCellLayout += new BeforeCellLayoutEventHandler(table_BeforeCellLayout);
        
        // Draw the table 
        table.Draw(page, new PointF(0, 0));
    
        // Save the PDF document to disk.
        doc.Save(@"c:\temp\customize table.pdf");
    
        // Use the following code to stream the document to the browser. 
        // pdfDoc.Save("customize table.pdf", Response, HttpResponseType.OpenInsideBrowser); // Response is an HttpResponse object.
    
        // Close the document.
        doc.Close();
    }
    
    static void table_BeforeCellLayout(object sender, BeforeCellLayoutEventArgs args)
    {
        if (args.CellIndex == 0 && (args.RowIndex % 2) == 1)
        {
            // Draw ellipses inside cells
            args.Graphics.DrawEllipse(PdfBrushes.Green, args.Bounds);
        }
    }
    
    static void table_BeforeRowLayout(object sender, BeforeRowLayoutEventArgs args)
    {
        if ((args.RowIndex % 2) == 0)
        {
            args.IgnoreColumnFormat = true;
        }
    }


    Saturday, May 03, 2014 5:07 PM