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

  • Home
  • SEARCH
  • 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 7017065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:51:59+00:00 2026-05-27T22:51:59+00:00

I have generated a pdf using iTextSharp, when its created it saves automatically in

  • 0

I have generated a pdf using iTextSharp, when its created it saves automatically in the location provided in my code on the server not on the client side and of course without telling anything to the user.

I need to send it to the client and I need to prompt a dialogue box to ask the user where he wants to save his pdf..

how can i do this please?

this is my pdf code:

using (MemoryStream myMemoryStream = new MemoryStream())
{
    Document document = new Document();
    PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);

    document.AddHeader("header1", "HEADER1");


    document.Open();

      //..........

    document.Close();

    byte[] content = myMemoryStream.ToArray();

    // Write out PDF from memory stream.
    using (FileStream fs =      File.Create(HttpContext.Current.Server.MapPath("~\\report.pdf")))
    {
        fs.Write(content, 0, (int)content.Length);
    }

EDIT

this is an example of the result i want
http://examples.extjs.eu/?ex=download

thanks to your replies ,I modified my code to this:

HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader( "Content-Disposition", "attachment; filename=test.pdf");


using (MemoryStream myMemoryStream = new MemoryStream())
{    
Document document = new Document();    
PdfWriter PDFWriter = PdfWriter.GetInstance(document, myMemoryStream);

document.AddHeader("Content-Disposition", "attachment; filename=wissalReport.pdf");

document.Open();

  //..........

document.Close();


byte[] content = myMemoryStream.ToArray();
HttpContext.Current.Response.Buffer = false;  
HttpContext.Current.Response.Clear();         
HttpContext.Current.Response.ClearContent(); 
HttpContext.Current.Response.ClearHeaders();  
HttpContext.Current.Response.AppendHeader("content-disposition","attachment;filename=" + "my_report.pdf");                
HttpContext.Current.Response.ContentType = "Application/pdf";        

//Write the file content directly to the HTTP content output stream.    
HttpContext.Current.Response.BinaryWrite(content);         
HttpContext.Current.Response.Flush();                
HttpContext.Current.Response.End(); 

but i get this error:

Uncaught Ext.Error: You're trying to decode an invalid JSON String: 
%PDF-1.4 %���� 3 0 obj <</Type/XObject/Subtype/Image/Width 994/Height 185/Length 13339/ColorSpace/DeviceGray/BitsPerComponent 8/Filter/FlateDecode>>stream x���|E�
...........

im absolutely sure my itextsharp to create pdf is correct because i can save it on the server, but thats not what i need to do ,when i try to send it to the client i got the error above

thanks in advance

  • 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-27T22:52:00+00:00Added an answer on May 27, 2026 at 10:52 pm

    SOLVED

    The error is from the submit operation trying to interpret the response which it can not because it is not in a known format.

    I just set window.location to download files and this works fine.

    {
    xtype:'button',           
    text: 'Generate PDF',           
    handler: function () {
         window.location = '/AddData.ashx?action=pdf';                   
    }
    }
    

    Instead of setting the location you can also do window.open().

    Whether the file will be downloaded or opened depends on browser settings.

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

Sidebar

Related Questions

I have a PDF that is being generated from HTML source using HTMLDOC. While
I have a project which needs to generate PDF documents. I am using iTextSharp.
I have generated a pdf using fpdf library. The datas are exported to pdf
Im using ITextSharp to generate a PDF, and have a situation where a need
I have successfully generated password protected pdf using xsl fo from apache foundation's fop
I have a problem with some user provided pdf documents. They are created from
As weird as it may sound, the code that generated pdf using Prawn gem
I'm using iTextSharp to generate some PDF files. I have two tables which have
I generated latex template using perl,and complied with MikTeX, its generating pdf. But I
MVC3 VB.NET application using Itextsharp. I have a section of code that generates a

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.