Adersh
Adersh

Reputation: 1

iTextsharp pdf cannot open when hosting in IIS

I am using iTextSharp for creating PDF for reports in ASP.Net (c#). Pdf is created successfully & can be opened when running the Application, but when iam hosted in IIS it cannot open in PDF and gives error :

"adobe reader could not open pdf because it is either not a supported file type or because the file has been damaged "

My code like:

Document pdfDoc = new Document();
pdfDoc.SetPageSize(PageSize.A4.Rotate());

string filepath = "Demo" + ".pdf";

string attachment = "attachment; filename=" + filepath;
Response.Charset = String.Empty;
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/PDF";

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

//Adding some paragraph in to the pdfdoc.            

pdfDoc.Close();

Response.Write(pdfDoc);
Response.End();

I am waiting for your greatfull ideas

Upvotes: 0

Views: 1834

Answers (1)

Sergio
Sergio

Reputation: 11

I know that this an old post, but I had a problem with itextsharp, and in my case was about the folder permissions to the iis user.

I just right clicked on my main folder, went to the security tab and chose the .Net User(were 2 for me) and gave full control. And that was my problem, and solved. Hope this can help someone else.

Upvotes: 1

Related Questions