PDF generation reaches up to 100% and prints after 4~5 minutes
See original GitHub issueASP.NET core version: 1.1.2.
On other machines this code works normally. I’ve restarted and tried various configurations without success. I also printed an empty document, with no header and footer.
Startup.cs
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
Class that generates the report
//On constructor
_converter = new SynchronizedConverter(new PdfTools());
//On the method
var _diarioDeOperacao = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4Plus
}
};
_diarioDeOperacao.Objects.Add(new ObjectSettings()
{
PagesCount = true,
HtmlContent = "Teste",
WebSettings = { DefaultEncoding = "utf-8", LoadImages = false },
UseExternalLinks = false
});
_converter.Error += (sender, args) => _logger.LogError("Erro no relatório: Diário de operações\n" + args.Message);
_converter.Warning += (sender, args) => _logger.LogWarning("Warning no relatório: Diário de operações\n" + args.Message);
_converter.ProgressChanged += (sender, args) => _logger.LogWarning(args.Description);
_converter.Finished += (sender, args) => _logger.LogWarning("Sucesso " + args.Success);
//when debugging, here is where it hangs
byte[] pdfBytes = _converter.Convert(_diarioDeOperacao);
Response.ContentType = "Application/pdf";
Response.Headers.Remove("Content-Disposition");
Response.Headers.Add("Content-Disposition", $@"attachment; filename=Diario de Operacoes {DateTime.Now.ToString()}.pdf");
var buffer = pdfBytes;
Response.StatusCode = 200;
Response.Body.Write(buffer, 0, buffer.Length);
Response.Body.Flush();
Response.Body.Dispose();
Console output
#when the method is called it produces
Qt: Could not initialize OLE (error 80010106)
warn: PortoImbituba.Controllers.AccountController[0] 0%
warn: PortoImbituba.Controllers.AccountController[0] 10%
warn: PortoImbituba.Controllers.AccountController[0] 50%
warn: PortoImbituba.Controllers.AccountController[0] 100%
#after 4 minutes and 8 seconds
warn: PortoImbituba.Controllers.AccountController[0] Object 1 of 1
warn: PortoImbituba.Controllers.AccountController[0] Object 1 of 1
warn: PortoImbituba.Controllers.AccountController[0] Preparing
warn: PortoImbituba.Controllers.AccountController[0] Page 1 of 1
warn: PortoImbituba.Controllers.AccountController[0] Sucesso True
Issue Analytics
- State:
- Created 5 years ago
- Comments:10
Top Results From Across the Web
How to Handing EXTREMELY Large Strings in PHP When ...
I found that if my blocks of HTML went over 20,000 characters the PDF would take well over 2 minutes to generate. I...
Read more >Print to PDF in Outlook Creates Endless Notepad Files w
I am creating a document in Word, then printing it to PDF. Then, Note pad explodes with an endless creation of the below...
Read more >How to AUTOMATICALLY Fill PDF Forms Using ... - YouTube
GET THIS +300 OF MY BEST TEMPLATES HERE▻ https://bit.ly/300WKBK-Desc BRING AI INTO EXCEL WITH THIS INCREDIBLE ADD- IN ▻ ...
Read more >Printing PDF's, and how to size and resize. - YouTube
How to print a PDF pattern or document and how to resize it if you wish. How to print pdf files from computer...
Read more >Known issues with PaperCut MF, NG, Hive ...
PaperCut provides simple and affordable print management software for ... longer than 1 minute to install show as "failed" in the Print Deploy...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a similar problem a while ago.
You’re not using the the converter you added as singleton in Startup.cs. You’re creating a new SynchronizedConverter and PdfTools every time your class instantiates. I think this causes issues because you’re ending up creating multiple instances of PdfTools without disposing them. (PdfTools implements IDisposable).
I would change your constructor to retrieve the converter from the services by dependency injection instead.
Perhaps something like this:
Well, it seems to be problem with the DinkToPdf…
I guess that is something about making a singleton instance receive a IDisposable class (PdfTools)
I just made this code and worked like a charm: