nopCommerce 3.0 - Add logo to packing slip

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi,

How would I go about adding a logo to the pdf packing slip in nopCommerce 3.0?

Thank,
Rhek
10 years ago
I believe you need to go to:

Configuration -> Settings ->General and miscellaneous settings -> pdf settings

Thanks,
Chris
10 years ago
That seems to take care of it for the invoice, but for some reason it does not for the packing slip. :(
10 years ago
It would require custom programming

In
  \Libraries\Nop.Services\Common\PdfService.cs
Only
  public virtual void PrintOrdersToPdf
references the logo.

This does not
  public virtual void PrintPackagingSlipsToPdf
10 years ago
You're right, I forgot I had to make some changes for it.  Looking through source control, it looks like I made the following changes:

I added the following code to "Libraries/Nop.Services/Common/PdfService.cs" in the function "PrintPackagingSlipsToPdf(....):




foreach (var shipment in shipments)
            {
                var order = shipment.Order;

                if (languageId == 0)
                {
                    lang = _languageService.GetLanguageById(order.CustomerLanguageId);
                    if (lang == null || !lang.Published)
                        lang = _workContext.WorkingLanguage;
                }

                #region Header

                //logo
                var logoPicture = _pictureService.GetPictureById(_pdfSettings.LogoPictureId);
                var logoExists = logoPicture != null;

                //header
                var headerTable = new PdfPTable(logoExists ? 2 : 1) {WidthPercentage = 100f};
                if (logoExists)
                    headerTable.SetWidths(new[] { 50, 50 });

                //logo
                if (logoExists)
                {
                    var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                    var logoFile = Image.GetInstance(logoFilePath);
                    logoFile.ScaleToFit(220, 60);
                    var cellLogo = new PdfPCell(logoFile);
                    cellLogo.Border = Rectangle.NO_BORDER;
                    headerTable.AddCell(cellLogo);
                }
     #endregion


I customized some other stuff in there (store specific), but I don't think you'll need anything else.  Let me know if you have an y problems.

Thanks,
Chris
10 years ago
Thanks! That was exactly what I needed.
10 years ago
Hi guys,

I want to edit mi PDF invoice, but I dont know where is "Libraries  - > Nop.Services - > Common - > PdfService.cs" directory... can you help me please? on my hosting directory I dont have it...

Regards,

Felix
10 years ago
This change requires that you modify source code and recompile.  Do you have the source code from codeplex?

Thanks, Chris
9 years ago
I had to do more than this in order to get it to work for me. The code above in this thread was not enough to get the Logo to show up on the PDF packing slips of mine - I'm using nopCommerce 3.4. Here's what worked for me after several rounds of testing and debugging:

In the PrintPackagingSlipsToPdf method in the PdfService class in Nop.Services.Common, find the code below

foreach (var shipment in shipments)
            {
                var order = shipment.Order;
                
                if (languageId == 0)
                {
                    lang = _languageService.GetLanguageById(order.CustomerLanguageId);
                    if (lang == null || !lang.Published)
                        lang = _workContext.WorkingLanguage;
                }

And then insert this directly after this code (inside of this foreach):

#region Header

                //logo
                var logoPicture = _pictureService.GetPictureById(_pdfSettings.LogoPictureId);
                var logoExists = logoPicture != null;

                //header
                var headerTable = new PdfPTable(logoExists ? 2 : 1) { WidthPercentage = 100f };
                if (logoExists)
                    headerTable.SetWidths(new[] { 50, 50 });

                //logo
                if (logoExists)
                {
                    var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                    Image logoFile = Image.GetInstance(logoFilePath);
                    logoFile.ScaleToFit(220, 60);
                    var cellLogo = new PdfPCell(logoFile) {Border = Rectangle.NO_BORDER};
                    headerTable.AddCell(cellLogo);
                    var emptyCell = new PdfPCell {Border = Rectangle.NO_BORDER};
                    headerTable.AddCell(emptyCell);
                }
                doc.Add(headerTable);

                #endregion

Two key things were missing from the code in the answer above: doc.Add(headerTable); and the insertion of an empty cell (don't know why this was necessary to get the image to actually show up:

var emptyCell = new PdfPCell {Border = Rectangle.NO_BORDER};
headerTable.AddCell(emptyCell);

Thanks,
Jordan
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.