none
How to create a pdf from a form RRS feed

  • Question

  • I want my form to crate a pdf document.

    How do I do that?

    Do i need to add directives or references?


    Wednesday, September 25, 2019 6:34 PM

All replies

  • See the link above Search related threads?

    Please confirm if none of those list solutions help you first.

      

    Many thanks,
    Pete


    #PEJL
    Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to TechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

    Have you got what it takes to become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

    Wednesday, September 25, 2019 10:13 PM
    Moderator
  • Hi Jordanhal,

    Thank you for posting here.

    If you want to create a pdf from a form, yes you need to add a reference.

    You can install iTextSharp through NuGet Package Manager as below:

    Tools  =>  NoGet Package Manager  =>  NoGet Package Manager for Solution.

    And then, you can try the following code to do that.

    using iTextSharp.text;
    using iTextSharp.text.pdf;
    
    private void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    using (FileStream stream = new FileStream(@"D:\test\a.pdf", FileMode.OpenOrCreate))
                    {
                        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
                          PdfWriter writer = PdfWriter.GetInstance(document, stream);
    
                          document.Open();
                          document.Add(new Paragraph("PDF1, PDF1, PDF1, PDF1, PDF1"));
                          document.Add(new Paragraph("PDF1, PDF1, PDF1, PDF1, PDF1"));
                          document.Add(new Paragraph("PDF1, PDF1, PDF1, PDF1, PDF1"));
                          document.Add(new Paragraph("PDF1, PDF1, PDF1, PDF1, PDF1"));
                        
                          document.NewPage();
                          document.Close();
                        MessageBox.Show("Add Success.");
                    }
                }
                catch (Exception)
                {
    
                    throw;
               }
               
            }
    

    Best Regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 26, 2019 2:40 AM
    Moderator