1. nopCommerce version - 4.6.0 (download) 2. Expected behavior - Create Invoice PDF with company logo 3. Actual behavior - Error - "The data buffer was empty." and no invoice PDF 4. Steps to reproduce the problem
a. Configuration\Settings\Pdf - Check PDF logo, upload a file (check blob file exist nnnnnnn_filename_thumbsize.fileext) b. Click Save c. Clear Cache d. Sales\Orders\Order - Invoice (PDF) - receive error (check blob file exist nnnnnnn_filename.fileext) e. Exception
System.ArgumentException: The data buffer was empty. at SkiaSharp.SKImage.FromEncodedData(Byte[] data) at QuestPDF.Fluent.ImageExtensions.Image(IContainer parent, Byte[] imageData, ImageScaling scaling) at Nop.Services.Common.Pdf.InvoiceDocument.<ComposeHeader>b__4_1(RowDescriptor row) in D:\users\***\source\repos\***\****\src\Libraries\Nop.Services\Common\Pdf\InvoiceDocument.cs:line 124
5. Any private modifications you made to your nopCommerce
Thanks for the quick response. I tried uploading various valid png and jpeg images, but all had the same issue. My images are stored in the file system (cloud) - Media Settings/Common - Pictures are stored into... file system: checked.
The Source.LogoData byte array is empty when it attempts to compose the header. Going back up the stack, the PrintOrderToPdfAsync method attempts to load logoFilePath (http://bloblocation/content/filename.fileext) using System File object, but will fail as file does not exist on system, but in the cloud.
Current: if (Source.LogoData is not null) logoContainer.Image(Source.LogoData, ImageScaling.FitArea);
Proposed Change: (Doesn't solve problem of logo.png not printing) if (Source.LogoData is not null && Source.LogoData.Length != 0) logoContainer.Image(Source.LogoData, ImageScaling.FitArea);
Full Error Message:
System.ArgumentException: The data buffer was empty. at SkiaSharp.SKImage.FromEncodedData(Byte[] data) at QuestPDF.Fluent.ImageExtensions.Image(IContainer parent, Byte[] imageData, ImageScaling scaling) at Nop.Services.Common.Pdf.InvoiceDocument.<ComposeHeader>b__4_1(RowDescriptor row) at QuestPDF.Fluent.RowExtensions.Row(IContainer element, Action`1 handler) at Nop.Services.Common.Pdf.InvoiceDocument.ComposeHeader(IContainer container) at QuestPDF.Fluent.ElementExtensions.Element[TParent](TParent parent, Action`1 handler) at Nop.Services.Common.Pdf.InvoiceDocument.<Compose>b__11_0(PageDescriptor page) at QuestPDF.Fluent.PageExtensions.Page(IDocumentContainer document, Action`1 handler) at Nop.Services.Common.Pdf.InvoiceDocument.Compose(IDocumentContainer container) at QuestPDF.Drawing.DocumentGenerator.RenderDocument[TCanvas](TCanvas canvas, IDocument document) at QuestPDF.Drawing.DocumentGenerator.GeneratePdf(Stream stream, IDocument document) at QuestPDF.Fluent.GenerateExtensions.GeneratePdf(IDocument document, Stream stream) at Nop.Services.Common.PdfService.PrintOrderToPdfAsync(Stream stream, Order order, Language language, Store store, Vendor vendor) at Nop.Services.Common.PdfService.PrintOrderToPdfAsync(Stream stream, Order order, Language language, Store store, Vendor vendor) at Nop.Services.Common.PdfService.PrintOrdersToPdfAsync(Stream stream, IList`1 orders, Language language, Vendor vendor) at Nop.Services.Common.PdfService.PrintOrdersToPdfAsync(Stream stream, IList`1 orders, Language language, Vendor vendor) at Nop.Services.Common.PdfService.PrintOrdersToPdfAsync(Stream stream, IList`1 orders, Language language, Vendor vendor) at Nop.Web.Areas.Admin.Controllers.OrderController.PdfInvoiceSelected(String selectedIds) in C:\Users\Development\nopCommerce\src\Presentation\Nop.Web\Areas\Admin\Controllers\OrderController.cs:line 1053 at Nop.Web.Areas.Admin.Controllers.OrderController.PdfInvoiceSelected(String selectedIds) in C:\Users\Development\nopCommerce\src\Presentation\Nop.Web\Areas\Admin\Controllers\OrderController.cs:line 1055
You may want to consider a byte[0] check on the SaveThumgAsync in PictureServices.cs line 273:
Current: if (Source.LogoData is not null) logoContainer.Image(Source.LogoData, ImageScaling.FitArea);
Proposed Change: (Doesn't solve problem of logo.png not printing) if (Source.LogoData?.Length > 0) logoContainer.Image(Source.LogoData, ImageScaling.FitArea);