user1947393
user1947393

Reputation: 313

Generate temporary pdf and display it in object tag

I want to generate a pdf file using the iTextSharp, then I want to dispaly this file in object tag. Here my code to generate the pdf:

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);    

    pdfDoc.Open();

    Paragraph Title = new Paragraph("New Paragraph");
    pdfDoc.Add(Title);

    pdfDoc.Close(); 

    Response.ContentType = "application/pdf";

    Response.AddHeader("content-disposition", "attachment;" +

                                   "filename=sample.pdf");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Response.Write(pdfDoc);

    Response.End();

but this code is generating a pdf file and show save/open dialogue which I don't want. I want it to be generated and then be displayed in the object tag without the dialogue and without to save it on my folders.

Upvotes: 0

Views: 806

Answers (2)

user1947393
user1947393

Reputation: 313

It works with "inline", Thank you all

Upvotes: 0

Markus
Markus

Reputation: 22436

The relevant line is the following:

Response.AddHeader("content-disposition", "attachment;filename=sample.pdf");

By setting content-disposition to attachment, you specify that the browser should require some user interaction (see this link for details and other possible values).

If you change the value to inline, the browser should display the element as you desire:

Response.AddHeader("content-disposition", "inline;filename=sample.pdf");

Upvotes: 1

Related Questions