Click here to Skip to main content
14,456,907 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to generate pdf file using C#. Please help me out.

What I have tried:

i have no idea of solution. Please give me relevant answer to solve the issue.
Updated 8-Jan-20 18:48pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

I have a good experience with PDFsharp and MigraDoc[^].

It's free and there are number of examples on their site and on the internet.

Good luck!
Rate this:
Please Sign up or sign in to vote.

Solution 2

There are two ways you could do this. The first is to study the PDF specification and use that to build the documents that way. That, however, is a silly way to do this.

The second way is to use a component that writes the PDF for you, based on the calls you make. There are a number of commercial or free PDF generation libraries available to you, each having their own strengths and weaknesses. You might want to look at something like PDFSharp[^] or the ever popular iTextSharp[^].
Rate this:
Please Sign up or sign in to vote.

Solution 6

try this method for generate pdf using c#.
first Install-Package iTextSharp after used this method.
protected void GeneratePDF(object sender, System.EventArgs e)
         using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
             Document document = new Document(PageSize.A4, 10, 10, 10, 10);

             PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);

             Chunk chunk = new Chunk("This is from chunk. ");

             Phrase phrase = new Phrase("This is from Phrase.");

             Paragraph para = new Paragraph("This is from paragraph.");

             string text = @"you are successfully created PDF file.";
             Paragraph paragraph = new Paragraph();
             paragraph.SpacingBefore = 10;
             paragraph.SpacingAfter = 10;
             paragraph.Alignment = Element.ALIGN_LEFT;
             paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 12f, BaseColor.GREEN);

             byte[] bytes = memoryStream.ToArray();
             Response.ContentType = "application/pdf";

             string pdfName = "User";
             Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfName + ".pdf");
             Response.ContentType = "application/pdf";
             Response.Buffer = true;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100