tuespetre / TuesPechkin

A .NET wrapper for the wkhtmltopdf library with an object-oriented API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in MVC solutions using NuGet package

mistral61 opened this issue · comments

I'm working on a solution .NET 4.5, knockout.js, MVC where is used the NuGet component, Visual Studio Community 2017 with the latest updates, pc with Windows 10.
The NuGet package is 2.1.1, there is another package TuesPechkin.Wkhtmltox.AnyCPU 0.12.4.1
I'm new to this project which is 5 years old, written by other persons no more working here: I never used knockout before, for PDF printing from web I used in the past Crystal reports, something with ITextSharp; never heard of TuesPechkin...
On the customer test and production sites, under Windows Server, the PDF generation is working.
On my pc I have troubles, I get the error "The argument type 'TuesPechkin.WinAnyCPUEmbeddedDeployment' cannot be converted into parameter type 'TuesPechkin.IDeployment'."
In practice, there is a controller

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult GenerateReport(string data)
        {
            try
            {
                var requestObj = JObject.Parse(data);
                var model = CreatePrintModel(requestObj);
                var res = new Html2Pdf().GeneratePdf(model);
                var fileName = requestObj["fileName"].Value<string>();
                if (!fileName.EndsWith(".pdf"))
                    fileName += ".pdf";
                Response.AddHeader("Content-Disposition", $"inline; filename={fileName}");
                return File(res, "application/pdf");
            }
            catch (Exception ex)
            {
                // code for log
            }
        }

the error happens on GeneratePdf, which is

        public byte[] GeneratePdf(PrintModel printModel)
        {
            using(var context = new FileDeleterContext())
            {
                foreach(var docHtml in printModel.Documents)
                {
                    if(!string.IsNullOrEmpty(docHtml.HeaderHtml))
                        docHtml.HeaderTempUrl = $"file:///{context.CreateTempFile(docHtml.HeaderHtml)}";
                    if(!string.IsNullOrEmpty(docHtml.FooterHtml))
                        docHtml.FooterTempUrl = $"file:///{context.CreateTempFile(docHtml.FooterHtml)}";
                }
                var document = new HtmlToPdfDocument
                {
                    GlobalSettings = MakeGlobalSettings(printModel)
                };
                var objects = printModel.Documents.Select(MakeObjectSettings);
                document.Objects.AddRange(objects);
                return Converter.Convert(document);
            }
        }

the error line is the latest code of line, return Converter.Convert(document);
Someone could hint what could be the problem?