You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I've been spending a couple days beating my head over this library, trying to get simple HTML to render correctly. b tags don't seem to work sometimes, there are frequent missing blocks of text, or white-on-white renderings. It's a great start but it's really not production ready. Its also really long in the tooth, only supporting HTML 4.01.
If you just need something quick, easy, and free, and actually working to convert HTML to PDF just use Chrome:
try{vartempPath=Path.Combine(Path.GetTempPath(),"AHYAPI");Directory.CreateDirectory(tempPath);//Im using a cshtml render service, but your HTML file can come from anywherestringhtml=await_razorRenderService.GetTemplateHtmlAsStringAsync("OrderConfirmationPdf",model);varhtmlPath=Path.Combine(tempPath,$"OrderPDF_{model.Order.OrderNumber}.html");varpdfPath=Path.Combine(tempPath,$"OrderPDF_{model.Order.OrderNumber}.pdf");File.WriteAllText(htmlPath,html);if(File.Exists(pdfPath)){File.Delete(pdfPath);}ProcessStartInfops=newProcessStartInfo(){FileName=@"C:\Program Files\Google\Chrome\Application\chrome.exe",WorkingDirectory=Path.GetDirectoryName(_settings.PathToChromeExe),UseShellExecute=false,};ps.ArgumentList.Add("--headless");ps.ArgumentList.Add("--disable-gpu");ps.ArgumentList.Add($"--user-data-dir={Path.Combine(Path.GetDirectoryName(pdfPath),"Chrome\\")}");ps.ArgumentList.Add("--print-to-pdf-no-header");//Remove this line if you want page numbers and other goops.ArgumentList.Add($"--print-to-pdf={pdfPath}");ps.ArgumentList.Add(htmlPath);Processconverter=Process.Start(ps);if(!converter.WaitForExit(20000)){converter.Kill();}if(converter.ExitCode!=0){Console.WriteLine("An error occurred.");}else{//This bit will launch the PDF in your viewer. this part isn't required though.ProcessStartInfops2=newProcessStartInfo(){UseShellExecute=true,FileName=pdfPath};Process.Start(ps2);}}catch(Exceptionex){Console.WriteLine($"An error occurred: {ex.Message}");}
The text was updated successfully, but these errors were encountered:
So, I've been spending a couple days beating my head over this library, trying to get simple HTML to render correctly. b tags don't seem to work sometimes, there are frequent missing blocks of text, or white-on-white renderings. It's a great start but it's really not production ready. Its also really long in the tooth, only supporting HTML 4.01.
If you just need something quick, easy, and free, and actually working to convert HTML to PDF just use Chrome:
The text was updated successfully, but these errors were encountered: