Pechkin
Pechkin copied to clipboard
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
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)
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;
}
}
I had the same problem and the static trick isn't working for me.
3 years old, but still... did you end up working this one out?
Please assist as we are also interested in a solution for this.