腐敗的PDF我都tryed,但仍然沒有工作iTextSharp的是生產與響應
iTextSharp + FileStream = Corrupt PDF file
iTextSharp is producing a corrupt PDF
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
//abre o documento para poder editar
document.Open();
//Adiciona os campos de assinatura
document.Add(Assinatura());
//fecha o documento ao finalizar a edição
document.Close();
//Prepara o download
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "image/pdf";
//Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;
filename=ControleDePonto.pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
什麼即時做錯了什麼?
'application/pdf'是正確的MIME類型。見[這個問題](http://stackoverflow.com/questions/312230/proper-mime-media-type-for-pdf-files)。順便說一句,沒有必要關閉響應。 – mason
我也試過了,但沒有成功 –
剛纔注意到,你永遠不會將信息從'document'傳遞到你的內存流中。 – mason