0
當我的用戶單擊鏈接時,我想爲PDF提供標準的打開/保存對話框,而不是在瀏覽器中打開它...使用ffg代碼生成PDF:當pdf在瀏覽器中打開時提供打開/保存選項
Document document = new Document();
MemoryStream stream = new MemoryStream();
try
{
PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
pdfWriter.CloseStream = false;
document.Open();
document.Add(new Paragraph("Hello World"));
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
document.Close();
stream.Flush();
stream.Position = 0;
return File(stream, "application/pdf");
只是一種猜測,但Response.AddHeader(「內容-Disposition「,」attachment; filename = \ 「」+ attachment.AttachmentName()+「\」「);根據這一點,不是提供PDF類型的內容,而是創建PDF附件,並提示用戶保存或查看 – davethecoder