Pechkin icon indicating copy to clipboard operation
Pechkin copied to clipboard

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Open fscopel opened this issue 9 years ago • 4 comments

I get this random error, any ideas where to start?

Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

StackTrace: at Pechkin.PechkinBindings.wkhtmltopdf_convert(IntPtr converter) at Pechkin.PechkinStatic.PerformConversion(IntPtr converter) at Pechkin.SimplePechkin.Convert(ObjectConfig doc, Byte[] html) at Pechkin.SimplePechkin.Convert(ObjectConfig doc, String html) at Pechkin.Synchronized.SynchronizedPechkin.<Convert>b__2(IPechkin conv, ObjectConfig obj, String txt)

fscopel avatar Feb 26 '15 19:02 fscopel

Aye you sure it is random? I was getting the same error. The first time a PDF was generated it would work fine, anytime after that I got the error above. It was in a web project and due to bad configuration as far as I could tell. Here is what I have for IIS that works fine:

    private byte[] GetPdfBytes(Quote quote, GetQuoteOutput quoteOutput, Tenant tenant)
    {
        string partialView = string.Format("PDF/Tennants/{0}/Template{1}", this.CurrentSession.TenantId,
            quote.TemplateId);

        string htmlText = RenderPartialViewToString(this, partialView, quoteOutput.Quote);

        string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
        string headerUrl = string.Format(baseUrl + "/tenantfiles/{0}/header.html", tenant.TenancyName);
        string footerUrl = string.Format(baseUrl + "/tenantfiles/{0}/footer.html", tenant.TenancyName);

        //IPechkin pechkin = Factory.Create();

        var document = new HtmlToPdfDocument
        {
            GlobalSettings =
            {
                ProduceOutline = true,


                DocumentTitle = "Quote - " + quoteOutput.Quote.Reference,
                Margins =
                {
                    Top = 3,
                    Right = 1,
                    Left = 1,
                    Bottom = 3.4,
                    Unit = Unit.Centimeters
                }
            },
            Objects =
            {
                new ObjectSettings
                {
                    HtmlText = htmlText,
                    HeaderSettings = new HeaderSettings() {HtmlUrl = headerUrl, ContentSpacing = 6},
                    FooterSettings =
                        new FooterSettings
                        {
                            HtmlUrl = footerUrl,
                            RightText = "[page]/[toPage]",
                            FontSize = 9,
                            FontName = "Trebuchet MS",
                            ContentSpacing = 10
                        }
                }
            }
        };

        // Keep the converter somewhere static, or as a singleton instance!
        // Do NOT run the above code more than once in the application lifecycle!

        byte[] pdfBytes = HtmlToPdfConverter.Converter.Convert(document);

        return pdfBytes;
    }

}

brendan-rice avatar Mar 05 '15 23:03 brendan-rice

I had the same problem and the static trick isn't working for me.

2016-02-19 17_26_25-2016-02-19 16_33_03-view detail png - windows photo viewer

sanore avatar Feb 19 '16 16:02 sanore

3 years old, but still... did you end up working this one out?

miyagisan221b avatar Jan 22 '19 09:01 miyagisan221b

Please assist as we are also interested in a solution for this.

campbellja avatar Apr 08 '19 02:04 campbellja