manikanth

manikanth

  • NA
  • 6
  • 4.2k

creating pdf

Jun 15 2014 6:27 AM
in my project when click a button i need to open a new pdf file, in that file contain values from my database. how to create it. please help me

Answers (3)

0
Glen Lewis

Glen Lewis

  • 0
  • 20
  • 0
Jul 9 2014 4:04 AM
Hi manikanth, I'm not sure if you want to create a new PDF from scratch in C# or do you want to use some sort of a template document.
You see this second approach is more common, you could create a word (DOCX) or template (DOTX) document in .NET which will define some place holders and then you can fill them with database data and convert the document to a PDF.
I also used this approach with a help of this .net dll for word and other document type file processing, more specific I used MergeField elements in DOTX file and then execute a mail merge operation in C# to import new data, after that I save the document into a PDF format.
Also just in case if that approach does not suit your needs, here is a sample how to create a new PDF file with DataTable's data:
var dataTable = new DataTable();

// ...

var document = new DocumentModel();
document.Sections.Add(
    new Section(document,
        new Table(document, dataTable.Rows.Count, dataTable.Columns.Count,
                    (r, c) => new TableCell(document,
                                    new Paragraph(document, dataTable.Rows[r][c].ToString())))));

document.Save("New File.pdf");
I hope this helps.
0
Rahul  Prasad

Rahul Prasad

  • 0
  • 615
  • 60
Jun 30 2014 11:09 PM
here provides various ways to export database data to PDF in C#

http://www.codeproject.com/Questions/385812/How-to-export-data-to-PDF-using-csharp
0
Anupam Singh

Anupam Singh

  • 336
  • 4.9k
  • 1.7m
Jun 15 2014 10:41 AM
You can try ItextSharp , find a simple use here:
http://www.codeproject.com/Articles/81118/ITextSharp-Helper-Class