C# PDF未保存在Chrome中,但保存在FireFox中
我现在遇到的情况是,我正在使用iTextSharp生成一个PDF,但当它在新浏览器选项卡中打开时,它会提供打印、保存、放大、缩小等选项 除“保存”外,所有其他默认功能(如打印、缩放)都正常工作。当我单击“保存”按钮时,它不会保存该文档。我也尝试使用CTRL+S,但结果相同 这是我的密码:C# PDF未保存在Chrome中,但保存在FireFox中,c#,asp.net-mvc,itextsharp,C#,Asp.net Mvc,Itextsharp,我现在遇到的情况是,我正在使用iTextSharp生成一个PDF,但当它在新浏览器选项卡中打开时,它会提供打印、保存、放大、缩小等选项 除“保存”外,所有其他默认功能(如打印、缩放)都正常工作。当我单击“保存”按钮时,它不会保存该文档。我也尝试使用CTRL+S,但结果相同 这是我的密码: public override void ExecuteResult(ControllerContext context) { IView viewEngineResul
public override void ExecuteResult(ControllerContext context)
{
IView viewEngineResult;
ViewContext viewContext;
if (ViewName == null)
{
ViewName = context.RouteData.GetRequiredString("action");
}
context.Controller.ViewData.Model = Model;
if (context.HttpContext.Request.QueryString["html"] != null &&
context.HttpContext.Request.QueryString["html"].ToLower().Equals("true"))
{
viewEngineResult = ViewEngines.Engines.FindView(context, ViewName, null).View;
viewContext = new ViewContext(context, viewEngineResult, context.Controller.ViewData,
context.Controller.TempData, context.HttpContext.Response.Output);
viewEngineResult.Render(viewContext, context.HttpContext.Response.Output);
}
else
{
var workStream = new MemoryStream();
var document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, workStream);
writer.CloseStream = false;
document.Open();
viewEngineResult = ViewEngines.Engines.FindView(context, ViewName, null).View;
var sb = new StringBuilder();
TextWriter tr = new StringWriter(sb);
viewContext = new ViewContext(context, viewEngineResult, context.Controller.ViewData,
context.Controller.TempData, tr);
viewEngineResult.Render(viewContext, tr);
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, stream, null);
document.Close();
new FileContentResult(workStream.ToArray(), "application/pdf").ExecuteResult(context);
}
我从上个小时就被这个问题困住了。帮帮我,伙计们
谢谢这不是与iTextSharp相关的问题:PDF中没有任何内容可以阻止用户保存文档。这是一个与浏览器相关的问题,所以您必须告诉我们您使用的浏览器和PDF插件(Adobe Reader?PDF.js?PDFium?)。我没有使用您提到的任何插件。浏览器是chrome。我刚刚在我的项目中包括了itextsharp和itextsharp.xmlWorker DLL。如果您使用的是Chrome,那么您使用的是PDFium(以前称为Chrome PDF viewer)。在另一个浏览器中尝试一下,它可能会工作。是的,它在Firefox中工作,但为什么它在CHrome中不工作。我如何才能使我工作。向谷歌提交一份bug报告。如果它在Firefox中工作,那么iText和代码都没有问题。如果它使用的是不同的浏览器/查看器(除了一个浏览器/查看器),那么罪魁祸首就是该浏览器/查看器。如何让它工作?你没有。您只需使用另一个浏览器/查看器,直到浏览器/查看器的提供程序解决问题。