skip to Main Content

I am trying to generate PDF from HTML data using NReco.PdfGenerator.

public static MemoryStream HtmlToPDFConvert(string html)
{
    HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter();
    pdfConverter.Size = NReco.PdfGenerator.PageSize.A4;
    var pdfBytes = pdfConverter.GeneratePdf(html);
    var ms = new MemoryStream(pdfBytes);
    return ms;
}

Code is working fine in my local machine, but I am getting below error when running code on server (plesk shared hosting).

System.Security.SecurityException: Request failed.     at MyClass.MyMethod(string arguments)     at b_Submit_Click(Object sender, EventArgs e)  The action that failed was:  LinkDemand  The type of the first permission that failed was:  System.Security.PermissionSet  The Zone of the assembly that failed was:  MyComputer

Looks like the error is because, NReco is trying to generate exe file for wkhtmltopdf but server is not allowing to generate that exe file.

Is there any way to solve this ? Thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    NReco was trying to generate exe file for wkhtmltopdf but server is not allowing to generate that exe file. So, I am now using iText library to generate PDF and it does not required any exe to be generated.

    Thanks for the help.


  2. You cannot use NReco.PdfGenerator on shared hosting because when you call GeneratePdf method wrapper executes wkhtmltopdf.exe with System.Diagnostics.Process API. On most shared hostings usage of this API is prohibited and it is not possible to start another processes from ASP.NET app.

    This limitation is mentioned in NReco.PdfGenerator’s FAQ ("Technical limitations").

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search