开发者

Recreating a new PDF still holds the old Image, using ASP.NET, C# and Winnovative.WnvHtmlConvert.PdfConverter

开发者 https://www.devze.com 2023-02-05 23:20 出处:网络
If I build a PDF (pdf1) with an image(image1), pdf1 shows image1 as expected. If I then replace image1 with image2, in the site, and make a new pdf2, pdf2 shows the old image1, and that\'s my (cachin

If I build a PDF (pdf1) with an image(image1), pdf1 shows image1 as expected.

If I then replace image1 with image2, in the site, and make a new pdf2, pdf2 shows the old image1, and that's my (caching?) problem.

For more information:

If I stop my program in VS and close all my Development Servers (Local ISS?), run the program again and make a new pdf (pdf3), the pdf3 shows the image2(the last image i made), which is correct.

So I guess i dont end some things or cache to much?

How I create the 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.CacheContr开发者_高级运维ol = "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();
    }

ProcessRequest

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 control

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

I spend a whole day on this now, any comments would be much appriciated.


Winnovative is grabbing the image from the cached under C:\Windows\Temp\Temporary Internet Files\Content.IE5 for IE9. This "windows" ie cache directory is different based on your version of IE.


It turnes out that it worked on another computer. So it must be my FF and Chrome settings or the function the browser has to handles PDF's that's no good. If anyone else care..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号