Convert .html file to .pdf encounters an exception

Convert .html file to .pdf encounters an exception

Forum member · May 3, 2021
Hi I am trying to convert a pdf file from html file. Sample HTML file looks like as shown below <!DOCTYPE html> <html> <body> <h1>Sample File Heading</h1> <p>This is the start of a paragraph.</p> </body> </html> C# code to convert html to pdf Uri uri1 = new Uri("file:///E:/PDFMerge/SampleHTML.html"); string outputFileX = @"E:\PDFMerge\MergedFiled12.pdf"; ceTe.DynamicPDF.HtmlConverter.ConversionOptions optionsC = new ceTe.DynamicPDF.HtmlConverter.ConversionOptions(ceTe.DynamicPDF.HtmlConverter.PageSize.A4, ceTe.DynamicPDF.HtmlConverter.PageOrientation.Portrait, 50.0f); // Set Metadata for the PDF optionsC.Header = "<div style=\"text-align:center;display:inline-block;width:100%;font-size:12px;\">" + "<span class=\"date\"></span></div>"; optionsC.Footer = "<div style=\"text-align:center;display:inline-block;width:100%;font-size:12px;\">" + "Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"; // Convert with Options Converter.Convert(uri1, outputFileX, optionsC); But i encounter an exception as shown below. Can you help me with this System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).) ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout) at ceTe.DynamicPDF.Conversion.DevTools.RuntimeCLI.Chrome.CreateNewSession() System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).) ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout) at ceTe.DynamicPDF.Conversion.DevTools.RuntimeCLI.Chrome.CreateNewSession() System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).) ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout) at ceTe.DynamicPDF.Conversion.DevTools.RuntimeCLI.Chrome.CreateNewSession() System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).) ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout) at ceTe.DynamicPDF.Conversion.DevTools.RuntimeCLI.Chrome.CreateNewSession() System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).) ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout) at ceTe.DynamicPDF.Conversion.DevTools.RuntimeCLI.Chrome.CreateNewSession() Exception thrown: 'System.AggregateException' in System.Private.CoreLib.dll An unhandled exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll

Re: Convert .html file to .pdf encounters an exception

Support · May 4, 2021
Hello, Thanks for sharing the code sample. We tested this on our end and are unable to recreate the error. Please try using latest version of the product on your end and see if that resolves the issue. You can download latest product from NuGet (Package ID: ceTe.DynamicPDF.HtmlConverter.NET) or from our website here . If you continue having this issue, please send over the following information to [^a|mailto:support@dynamicpdf.com|opennewwindow|support@dynamicpdf.com^] so we can investigate it further. 1. Environment under which the application is running. 2. Simple application which uses static data to recreate the error. 3. Steps needed to recreate the error. 4. Operating system details: Name, x86 or x64 5. Exact version and build number of the DynamicPDF.HtmlConverter product. You can find this information in DLL references properties (Version and Description field) in Visual Studio. Thanks, ceTe Software Support Team