简体   繁体   中英

IRONPDF taking 3 minutes to convert html to PDF

I am using below code to convert HTML to PDF using IRONPDF, but it is taking more than 3 minutes to get converted on application server , i am using : 1. License version 2. a simple html file to convert into pdf

        var infolder = textBox1.Text.Trim();
        var outfolder = textBox2.Text.Trim();

        var Renderer = new IronPdf.HtmlToPdf();
        var PDF = Renderer.RenderHTMLFileAsPdf(infolder);
        PDF.SaveAs(outfolder);

You should make sure that any external links (eg stylesheets, javascript) can be resolved from the machine where the rendering is happening. An easy way to check is to open the html file on that machine with a browser.

In our case, our staging environment was going through a load-balancer and the underlying servers couldn't resolve the name (eg https://staging-myapp.company.com ). We used a public gateway in our case but you could also modify your hosts file for your address to resolve locally (edit the hosts file with extreme caution!).

I suggest you Try to do in batches or for high performance. you can use Async and Threading

private async Task <IronPdf.PdfDocument>RenderPdfAsync( string Html , IronPdf.PdfPrintOptions PrintOptions = null )
{
  var Renderer = new IronPdf.HtmlToPdf();
  if(PrintOptions!=null){
    Renderer.PrintOptions = PrintOptions;
  }
  return Renderer.RenderHtmlAsPdf(Html);
}

Task.Run requires.Net Framework 4.5+

Or Using Parallel.ForEach

For high performance, IronPDF support multithreading . The easiest way to achieve this by using the native command Parallel.ForEach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM