Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Can no longer convert AspNetZero URL to PDF using SyncFusion HtmlToPdfConverter in Core 2.2 + Angular 8 v7.1.0 #7545


User avatar
0
wizgod created

Greetings Programs!

The following method works flawlessly in v7.0.0 for any url (application or external) but it breaks in v7.1.0 for any application url. It converts external urls as expected so there's nothing wrong with the conversion itself.

        public virtual void ConvertUrlToPDF(string url, string filename, string authToken = null, int minPageLoadTime = 30, string pageSize = "Letter", string orientation = "Portrait", int webPageWidth = 1024, int webPageHeight = 0, int marginTop = 20, int marginBottom = 20, int marginLeft = 20, int marginRight = 20)
        {
            var pdfPageSize = PdfPageSize.Letter;
            var pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), orientation, true);

            var settings = new WebKitConverterSettings
            {
                WebKitPath = Path.Combine(hostingEnvironment.ContentRootPath, "QtBinariesWindows"),
                WebKitViewPort = new Size(webPageWidth, webPageHeight),
                AdditionalDelay = minPageLoadTime * 1000,
                Margin = new PdfMargins { Left = marginLeft, Right = marginRight, Top = marginTop, Bottom = marginBottom },
                Orientation = pdfOrientation,
                PdfPageSize = pdfPageSize,
                SplitImages = false,
                SplitTextLines = true,
                TempPath = Path.GetTempPath()
            };

            if (!authToken.IsNullOrWhiteSpace())
            {
                settings.HttpRequestHeaders.Add("Authorization", $"bearer {authToken}");
            }

            //Initialize HTML to PDF converter and assign WebKit settings to HTML converter
            var htmlConverter = new HtmlToPdfConverter { ConverterSettings = settings };

            //Convert URL to PDF
            var document = htmlConverter.Convert(url);
            var stream = new MemoryStream();

            document.Save(stream);

            using (var file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write))
            {
                stream.WriteTo(file);
            }
        }

I generate the url and get the token from the cookie:

        let formUrl = AppConsts.appBaseUrl + '/#/app/main/form/' + this.form.formType.code.toLowerCase() + '/' + this.form.id + '/print';
        let authToken = abp.utils.getCookieValue('Abp.AuthToken');

The error is thrown by the converter:

Syncfusion.Pdf.PdfException: Failed to convert the webpage
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String url)

I'm thinking it might have something to do with the authorization header and token.

Thanks,

Wg


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wizgod

    • Are there any useful information in the full error message ?
    • Are there any other error message on the server side log file ?
  • User Avatar
    0
    wizgod created

    Hi @ismcagdas,

    Here is the log excerpt from the moment the export method is called to the resulting SyncFusion exception.

    Thanks,

    Wg

    INFO  2019-08-27 08:24:32,086 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://localhost:22742/api/services/app/Form/ExportFormToPdf  
    INFO  2019-08-27 08:24:32,086 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:24:32,086 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 0.2814ms 204 
    INFO  2019-08-27 08:24:32,366 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST http://localhost:22742/api/services/app/Form/ExportFormToPdf application/json 1096
    INFO  2019-08-27 08:24:32,367 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:24:32,369 [50   ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
    WARN  2019-08-27 08:24:32,370 [50   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:24:32,370 [50   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-08-27 08:24:32,370 [50   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:24:32,370 [50   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    INFO  2019-08-27 08:24:32,370 [50   ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application)'
    INFO  2019-08-27 08:24:32,397 [50   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {area = "app", action = "ExportFormToPdf", controller = "Form"}. Executing controller action with signature System.Threading.Tasks.Task`1[Wizgod.Dto.FileDto] ExportFormToPdf(Wizgod.Forms.Dto.ExportFormInput) on controller Wizgod.Forms.FormAppService (Wizgod.Application).
    INFO  2019-08-27 08:24:32,397 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:24:32,487 [50   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application) - Validation state: Valid
    INFO  2019-08-27 08:26:00,760 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://localhost:22742/AbpUserConfiguration/GetAll?d=1566915960687  0
    INFO  2019-08-27 08:26:00,760 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:00,760 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 0.3483ms 204 
    INFO  2019-08-27 08:26:00,770 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:22742/AbpUserConfiguration/GetAll?d=1566915960687  
    INFO  2019-08-27 08:26:00,770 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:00,771 [50   ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpLocalizationHeaderRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpLocalizationHeaderRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:26:00,771 [50   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    INFO  2019-08-27 08:26:00,772 [50   ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.GetAll (Abp.AspNetCore)'
    INFO  2019-08-27 08:26:00,778 [50   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "GetAll", controller = "AbpUserConfiguration", area = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.JsonResult] GetAll() on controller Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController (Abp.AspNetCore).
    INFO  2019-08-27 08:26:00,778 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:00,779 [50   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.GetAll (Abp.AspNetCore) - Validation state: Valid
    INFO  2019-08-27 08:26:00,818 [50   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.GetAll (Abp.AspNetCore), returned result Microsoft.AspNetCore.Mvc.JsonResult in 39.0194ms.
    INFO  2019-08-27 08:26:00,828 [66   ] matters.Json.Internal.JsonResultExecutor - Executing JsonResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
    INFO  2019-08-27 08:26:00,830 [66   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.GetAll (Abp.AspNetCore) in 52.0226ms
    INFO  2019-08-27 08:26:00,830 [66   ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Abp.AspNetCore.Mvc.Controllers.AbpUserConfigurationController.GetAll (Abp.AspNetCore)'
    INFO  2019-08-27 08:26:00,831 [66   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 60.9641ms 200 application/json; charset=utf-8
    INFO  2019-08-27 08:26:00,992 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://localhost:22742/api/services/app/Session/GetCurrentLoginInformations  0
    INFO  2019-08-27 08:26:00,994 [50   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:00,995 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 3.1187ms 204 
    INFO  2019-08-27 08:26:01,121 [66   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:22742/api/services/app/Session/GetCurrentLoginInformations  
    INFO  2019-08-27 08:26:01,121 [66   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:01,122 [66   ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
    WARN  2019-08-27 08:26:01,122 [66   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:26:01,122 [66   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-08-27 08:26:01,122 [66   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-08-27 08:26:01,122 [66   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    INFO  2019-08-27 08:26:01,125 [66   ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Wizgod.Sessions.SessionAppService.GetCurrentLoginInformations (Wizgod.Application)'
    INFO  2019-08-27 08:26:01,146 [66   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {area = "app", action = "GetCurrentLoginInformations", controller = "Session"}. Executing controller action with signature System.Threading.Tasks.Task`1[Wizgod.Sessions.Dto.GetCurrentLoginInformationsOutput] GetCurrentLoginInformations() on controller Wizgod.Sessions.SessionAppService (Wizgod.Application).
    INFO  2019-08-27 08:26:01,147 [66   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-08-27 08:26:01,156 [66   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Wizgod.Sessions.SessionAppService.GetCurrentLoginInformations (Wizgod.Application) - Validation state: Valid
    INFO  2019-08-27 08:26:01,181 [64   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Wizgod.Sessions.SessionAppService.GetCurrentLoginInformations (Wizgod.Application), returned result Microsoft.AspNetCore.Mvc.ObjectResult in 24.458ms.
    INFO  2019-08-27 08:26:01,184 [64   ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
    INFO  2019-08-27 08:26:01,184 [64   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Wizgod.Sessions.SessionAppService.GetCurrentLoginInformations (Wizgod.Application) in 37.9763ms
    INFO  2019-08-27 08:26:01,185 [64   ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Wizgod.Sessions.SessionAppService.GetCurrentLoginInformations (Wizgod.Application)'
    INFO  2019-08-27 08:26:01,185 [64   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 64.0329ms 200 application/json; charset=utf-8
    ERROR 2019-08-27 08:26:18,936 [66   ] Mvc.ExceptionHandling.AbpExceptionFilter - Failed to convert the webpage
    Syncfusion.Pdf.PdfException: Failed to convert the webpage
       at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String url)
       at Wizgod.Forms.FormAppService.ConvertUrlToPDF(String url, String filename, String authToken, Int32 minPageLoadTime, String pageSize, String orientation, Int32 webPageWidth, Int32 webPageHeight, Int32 marginTop, Int32 marginBottom, Int32 marginLeft, Int32 marginRight) in F:\Wizgod\aspnet-core\src\Wizgod.Application\Forms\FormAppService.cs:line 929
       at Castle.Proxies.Invocations.FormAppService_ConvertUrlToPDF.InvokeMethodOnTarget()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) in D:\Github\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 68
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Wizgod.Forms.FormAppService.ExportFormToPdf(ExportFormInput input) in F:\Wizgod\aspnet-core\src\Wizgod.Application\Forms\FormAppService.cs:line 825
       at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult[T](Task`1 actualReturnValue, Func`1 postAction, Action`1 finalAction)
       at lambda_method(Closure , Object )
       at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
       at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at System.Threading.Tasks.ValueTask`1.get_Result()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
    INFO  2019-08-27 08:26:18,947 [66   ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
    INFO  2019-08-27 08:26:18,950 [66   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application) in 106552.3423ms
    INFO  2019-08-27 08:26:18,950 [66   ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application)'
    INFO  2019-08-27 08:26:18,950 [66   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 106583.9302ms 500 application/json; charset=utf-8
    
  • User Avatar
    0
    wizgod created

    And here is the log of a successful export to pdf in v7.0.0:

    Thanks,

    Wg

    INFO  2019-06-10 10:09:29,243 [61   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST http://localhost:22742/api/services/app/Form/ExportFormToPdf application/json 854
    INFO  2019-06-10 10:09:29,243 [61   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-06-10 10:09:29,244 [61   ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
    WARN  2019-06-10 10:09:29,245 [61   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-06-10 10:09:29,245 [61   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-06-10 10:09:29,245 [61   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-06-10 10:09:29,245 [61   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    INFO  2019-06-10 10:09:29,245 [61   ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application)'
    INFO  2019-06-10 10:09:29,248 [61   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {area = "app", action = "ExportFormToPdf", controller = "Form"}. Executing action Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application)
    INFO  2019-06-10 10:09:29,248 [61   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-06-10 10:09:29,257 [61   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application) with arguments (Wizgod.Forms.Dto.ExportFormInput) - Validation state: Valid
    INFO  2019-06-10 10:09:29,347 [61   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application), returned result Microsoft.AspNetCore.Mvc.ObjectResult in 89.7744ms.
    INFO  2019-06-10 10:09:29,351 [61   ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
    INFO  2019-06-10 10:09:29,351 [61   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application) in 103.3478ms
    INFO  2019-06-10 10:09:29,352 [61   ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Wizgod.Forms.FormAppService.ExportFormToPdf (Wizgod.Application)'
    INFO  2019-06-10 10:09:29,352 [61   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 108.7065ms 200 application/json; charset=utf-8
    INFO  2019-06-10 10:09:29,449 [105  ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:22742/File/DownloadTempFile?fileType=application/pdf&fileToken=a1fdf3ce733e4bf7b5fb431e541a21fb&fileName=EA-011671.pdf  
    INFO  2019-06-10 10:09:29,450 [105  ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core)'
    INFO  2019-06-10 10:09:29,454 [105  ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "DownloadTempFile", controller = "File", area = ""}. Executing action Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core)
    INFO  2019-06-10 10:09:29,455 [105  ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core) with arguments (Wizgod.Dto.FileDto) - Validation state: Valid
    INFO  2019-06-10 10:09:29,456 [105  ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core), returned result Microsoft.AspNetCore.Mvc.FileContentResult in 0.5669ms.
    INFO  2019-06-10 10:09:29,456 [105  ] Infrastructure.FileContentResultExecutor - Executing Microsoft.AspNetCore.Mvc.FileContentResult, sending file with download name 'EA-011671.pdf' ...
    INFO  2019-06-10 10:09:29,456 [105  ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core) in 1.9169ms
    INFO  2019-06-10 10:09:29,456 [105  ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'Wizgod.Web.Controllers.FileController.DownloadTempFile (Wizgod.Web.Core)'
    INFO  2019-06-10 10:09:29,456 [105  ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 7.6059ms 200 application/pdf
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Is it possible to share a reproduction project via email (to [email protected]) ? It is hard to understand the problem using these logs.

    Thanks,

  • User Avatar
    0
    wizgod created

    I'll do my best to put something together.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @wizgod

    Would be great :)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wizgod

    I'm closing this issue. You can send the project to [email protected] when it is ready.