nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.2k stars 5.29k forks source link

Error when generating PDF with logo #6588

Closed RomanovM closed 1 year ago

RomanovM commented 1 year ago

nopCommerce version: 4.60

I have a custom store logo.png set to print on pdf. For some reason the thumb file was corrupted and 0 bytes. nopCommerce\src\Presentation\Nop.Web\wwwroot\images\thumbs\0000007_Logo_150.png (0bytes)

The following is line is throwing because data array is 0. \nopCommerce\src\Libraries\Nop.Services\Common\Pdf\InvoiceDocument.cs

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);

Stack trace:

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)

Source: https://www.nopcommerce.com/boards/topic/95950/generate-invoice-pdf-containing-graphical-logo

parshan2 commented 1 year ago

I couldn't reproduce the issue by set Pictures are stored into... setting to file system. I guess simultaneous access by the operating system prevents the files to be saved correctly. 🤷‍♂️🤷‍♂️🤷‍♂️

exileDev commented 1 year ago

Closed #6588

andreiborodin commented 10 months ago

The fix here simply hides the error/bug; the issue is that NopFileProvider fails to read a thumbnail from Azure Blob Storage. Here is the line of code:

PdfService.cs::PrintOrderToPdfAsync logo = await _fileProvider.ReadAllBytesAsync(logoFilePath);

DEWaller commented 5 months ago

The fix here simply hides the error/bug; the issue is that NopFileProvider fails to read a thumbnail from Azure Blob Storage. Here is the line of code:

PdfService.cs::PrintOrderToPdfAsync logo = await _fileProvider.ReadAllBytesAsync(logoFilePath);

Having just installed v4.60.6 I can confirm this is still a problem.

exileDev commented 5 months ago

Thank you, @andreiborodin! We have done it in #7151