Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:49:29+00:00 2026-05-26T22:49:29+00:00

I am using Itext Sharp to create pdf’s for a existing order on my

  • 0

I am using Itext Sharp to create pdf’s for a existing order on my site on a button click. It has been added as a web part on Sharepoint site.

On the Same Page , there is another web part with many server controls. But, when I click on any of the buttons , button click event is not triggerning. Only when I refresh the page, the event is getting triggered.

I am not able to simultaneously create a pdf and then immediately click on another button without page refresh. I dont understand what am I doing wrong.

Below is my code.

  protected void PdfGenerate_OnClick(object sender, EventArgs e)
  {
      Font Arial = FontFactory.GetFont("Arial", 12, BaseColor.BLACK);
      string imagename = "AAlogo.gif";
      string imagepath = Page.Server.MapPath("/_layouts/Images/ImagesFolder/Image1.gif" ) ;

      using (var ms = new MemoryStream())
      {
          using (var document = new Document(PageSize.A4,50,50,15,15))
          {
              PdfWriter.GetInstance(document, ms); 
              document.Open();
              Paragraph img = new Paragraph();
              Image aaImg = iTextSharp.text.Image.GetInstance(imagepath);
              img.Add(aaImg);
              img.IndentationRight = 5f;
              //code to add all the elements here  
              PdfPTable table = new PdfPTable(3);
              PdfPCell col1 = new PdfPCell(new Phrase("oRDER Number"));
              table.AddCell(col1);
              //  code for the table...
                  document.Add(table);
              }
             document.Close();
          }
          Response.Clear();
          Response.ContentType = "application/octet-stream";
          Response.AddHeader("content-disposition", "attachment;filename= Order Number" + .pdf");
          Response.Buffer = true; 
          Response.Clear();
          var bytes = ms.ToArray();
          Response.OutputStream.Write(bytes, 0, bytes.Length);
          Response.OutputStream.Flush();
      } 

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:49:30+00:00Added an answer on May 26, 2026 at 10:49 pm

    When you Clear and Flush the Response, you are interrupting/aborting asp.net’s page life cycle. It’s better to put that download section in another file (Page_Load of the separate file) and call it from the current page. more info: + and +

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using iTextsharp library to create PDF files. I can declare for A4 Landscape
I'm currently using ITextSharp to write a PDF to a web browser, but I
I am using iTextSharp to create a pdf in my ASP.NET 3.5 application. Below
I am using iTextSharp to create a PDF document in C#. I would like
How do one create PDF in memorystream instead of physical file using itextsharp. The
All I am inserting text in existing PDF file using iTextSharp Library, some times
I am trying to create a PDF using iTextSharp library (version 4.1.2.0). At the
I'm trying to create a pdf report using iTextSharp and I'm stumped as to
I am trying to create a pdf document in c# using iTextSharp 5.0.6. I
I'm using itextsharp with a aspmvc project to create PDF versions of some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.