title: Blazor pages generate HTML to PDF
body: <p>I want to print a rendered modal that opens up with some vehicle information, The button is present on the modal and on click should convert the modal HTML to PDF.</p>
  
  <p>Please advise if there is a C# function or so that I can use, which will extract the current HTML I want to convert to PDF, or steer me in the right direction. I have only been doing C# for about 2 months so lacking experience and expertise.</p>
  
  <p>Edit: Also trying to get the code to use CSS when dumping the PDF.</p>
  
  <p>I have added the following code.</p>
  
  <p>References, etc. added.</p>
  
  <pre><code>@using BidWheels.Configuration;
  @using BidWheels.Shared.Controls;
  @using BidWheels.Data;
  @using BidWheels.CustomProviders;
  @using BidWheels.Services;
  @using System.Timers;
  @using Syncfusion.Pdf;
  @using Syncfusion.HtmlConverter;
  @using System.Linq;
  @using System.Web;
  @using Microsoft.AspNetCore.Http;
  
  @inject AppState AppState;
  @inject UsersDAL UsersDAL;
  @inject MainDAL MainDAL;
  @inject NotificationService NotificationService;
  @inject GeneralConfiguration GeneralConfiguration;
  @inject GlobalVar GlobalVar;
  @inject GlobalVarShared GlobalVarShared;
  @inject Microsoft.JSInterop.IJSRuntime JS
  @inject IHttpContextAccessor httpContextAccessor
  </code></pre>
  
  <p>Button to proc the function to generate the PDF</p>
  
  <pre><code>        &lt;/div&gt;
          &lt;button class="btn btn-outline-success" @onclick="@CreatePDF"&gt;Generate PDF&lt;/button&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>This is the function invoked by the button.</p>
  
  <pre><code>@functions {
  
      void CreatePDF() 
      {
  
  &gt;         //Initialize HTML to PDF converter
  &gt;         //HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
  &gt;         //WebKitConverterSettings settings = new WebKitConverterSettings();
  &gt;         //Set WebKit path
  &gt;         //settings.WebKitPath = Server.MapPath("~/QtBinaries");
  &gt;         //Assign WebKit settings to HTML converter
  &gt;         //htmlConverter.ConverterSettings = settings;
  &gt;         //Get the current URL
  &gt;         //string url = HttpContext;
  &gt;         //Convert URL to PDF
  &gt;         //PdfDocument document = htmlConverter.Convert(url);
  &gt;         //Save the document
  &gt;         //document.Save("Sample.pdf", HttpContext.Current.Response, HttpReadType.Save);
  
  Code updated to below
          HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
          WebKitConverterSettings webKitSettings = new WebKitConverterSettings();
          webKitSettings.WebKitPath = Directory.GetCurrentDirectory() + "\\wwwroot" + @"\QtBinariesWindows\";
          webKitSettings.MediaType = MediaType.Print;
          webKitSettings.Orientation = PdfPageOrientation.Portrait;
          htmlConverter.ConverterSettings = webKitSettings;
          Convert HTML to PDF.
          string baseUrl = @"" + Directory.GetCurrentDirectory() + "/wwwroot/css/";
          string HTMLBody = await JS.InvokeAsync&lt;string&gt;("getHTMLtoRender", PDFBody);
          PdfDocument pdfDocument = htmlConverter.Convert(HTMLBody, baseUrl);
          MemoryStream memoryStream = new MemoryStream();
          Save and close the document instance.
          pdfDocument.Save(memoryStream);
          JS.SaveAs("Sample.pdf", memoryStream.ToArray());
  
      }
  
  }
  </code></pre>
  
  <p>The following errors are being generated.</p>
  
  <p>Error messages generated by the code for the above:</p>
  
  <p><a href="https://i.stack.imgur.com/wipV7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wipV7.png" alt="Error messages generated by the code for the above"></a></p>
  
  <p>New errors generated and lib:</p>
  
  <p><a href="https://i.stack.imgur.com/AgAAh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AgAAh.png" alt="New errors generated and lib"></a></p>