Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in MVC solutions using NuGet package #191

Open
mistral61 opened this issue Feb 10, 2021 · 0 comments
Open

Error in MVC solutions using NuGet package #191

mistral61 opened this issue Feb 10, 2021 · 0 comments

Comments

@mistral61
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant