开发者

Html to Pdf with iTextSharp creating pdf, but downloads as html+pdf

开发者 https://www.devze.com 2023-03-07 04:07 出处:网络
I can convert html files to pdfs with iTextSharp using code开发者_如何学编程 from Kyle in ITextSharp HTML to PDF?

I can convert html files to pdfs with iTextSharp using code开发者_如何学编程 from Kyle in ITextSharp HTML to PDF? The files save correctly and I can open them from Windows Explorer without a problem.

But when I then try to download one of the new pdfs with a very basic

Response.AppendHeader("content-disposition", "attachment; filename=" + fname);
Response.ContentType = type;
Response.WriteFile(fname);
Response.End();

the downloaded file won't open in Adobe. I opened it in a text editor and saw that what had actually come over was the full html code + the pdf code.

Why is the html inside the file (and only the downloaded version!) and how do I get rid of it?


I'm guessing you just need to do a Response.Clear() first to get rid of the rest of the page that is coming down the pipe.

0

精彩评论

暂无评论...
验证码 换一张
取 消