简体   繁体   中英

Html to Pdf with iTextSharp creating pdf, but downloads as html+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?

我猜想您只需要先执行Response.Clear()即可消除管道中其余的页面。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM