【问题标题】:Recreating a new PDF still holds the old Image, using ASP.NET, C# and Winnovative.WnvHtmlConvert.PdfConverter使用 ASP.NET、C# 和 Winnovative.WnvHtmlConvert.PdfConverter 重新创建新的 PDF 仍然保留旧图像
【发布时间】:2011-06-12 10:23:55
【问题描述】:

如果我使用图像 (image1) 构建 PDF (pdf1),pdf1 会按预期显示 image1。

如果我在站点中将 image1 替换为 image2,并制作一个新的 pdf2,pdf2 会显示旧的 image1,这就是我的(缓存?)问题。

更多信息:

如果我在 VS 中停止我的程序并关闭我所有的开发服务器(本地 ISS?),再次运行该程序并制作一个新的 pdf(pdf3),pdf3 显示 image2(我制作的最后一张图像),即正确。

所以我想我不会结束一些事情或缓存太多?


我如何创建 PDF

    public void CreateSingleFrontpage(string url)
    {
        var pdfConverter = new PdfConverter(0);
        PdfConverter.LayoutHtmlTimeoutSec = 500;
        pdfConverter.NavigationTimeout = 5000;

        pdfConverter.LicenseKey = "****************************";

        pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
        pdfConverter.PdfDocumentOptions.PdfCompressionLevel =
PdfCompressionLevel.Normal;
        pdfConverter.PdfDocumentOptions.PdfPageOrientation =
PDFPageOrientation.Portrait;
        pdfConverter.PdfDocumentOptions.ShowHeader = false;
        pdfConverter.PdfDocumentOptions.ShowFooter = false;
        pdfConverter.PdfDocumentOptions.LeftMargin = 80;
        pdfConverter.PdfDocumentOptions.RightMargin = 40;
        byte[] pdfBytes = pdfConverter.GetPdfBytesFromUrl(url);

        // send the PDF document as a response to the browser for download
        System.Web.HttpResponse response =
 System.Web.HttpContext.Current.Response;

        response.Clear();
        // response.CacheControl = "no-cache";
        response.AddHeader("Content-Type", "binary/octet-stream");
        response.AddHeader("Content-Disposition", "attachment; 
filename=PDF_Temp.pdf; size=" + pdfBytes.Length);
        response.Flush();
        response.BinaryWrite(pdfBytes);
        response.Flush();
        response.End();
    }


处理请求

public void ProcessRequest(HttpContext context)
    {
        int skemaId = int.Parse((context.Request.QueryString["SkemaId"]));
        int witchImage = int.Parse(context.Request.QueryString["witchImage"]);

        byte[] imageData = new BLL.Handlers.PDFForsideHandlers().GetImage(
witchImage, skemaId);
        if (imageData != null)
        {
            context.Response.ContentType = "image/jpg";
            context.Response.BinaryWrite(imageData);
//                context.Response.Flush();
//                context.Response.Clear();
//                context.Response.Close();
//                context.Response.End();
        }
    }


asp.net 控件

Image image = new Image();
image.ImageUrl = url;
image.DataBind();
PlaceHolder1.Controls.Add(image);


我现在花了一整天的时间,任何 cmet 都会非常感激。

【问题讨论】:

  • 我又做了一次浏览器测试,我想我的第一次测试不太好。它适用于 IE。到目前为止,我主要在FF中进行了测试。而且我现在可以看到它在 Chrome 中也不起作用。

标签: c# asp.net caching pdf pdf-generation


【解决方案1】:

事实证明它可以在另一台计算机上运行。所以一定是我的FF和Chrome设置或者浏览器处理PDF的功能不好。如果其他人在乎..

【讨论】:

    【解决方案2】:

    Winnovative 正在从缓存在 C:\Windows\Temp\Temporary Internet Files\Content.IE5 下为 IE9 抓取图像。这个“windows”即缓存目录会根据你的IE版本而有所不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 2021-09-25
      • 2013-09-26
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多