Insert an image in pdf invoice

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Hello everyone.

I need to add an QR-Code in the pdf invoice. It will be generated in the sourcecode itself.
But my Problem is, that I don't know exactly how I can add the image.

I don't want to safe the image before, because i will generate it before.

How can I do this?
3 years ago
KletterturmWeizenkirchen wrote:
Hello everyone.

I need to add an QR-Code in the pdf invoice. It will be generated in the sourcecode itself.
But my Problem is, that I don't know exactly how I can add the image.

I don't want to safe the image before, because i will generate it before.

How can I do this?


I think you can check the default flow on pdfservice >printHeader
var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                var logo = Image.GetInstance(logoFilePath);
                logo.Alignment = GetAlignment(lang, true);
                logo.ScaleToFit(65f, 65f);

                var cellLogo = new PdfPCell { Border = Rectangle.NO_BORDER };
                cellLogo.AddElement(logo);
                headerTable.AddCell(cellLogo);

Like this you can add code and Generate in that file only and you can send in PDF or as per your needed
3 years ago
Thanks!

So I want a new qr code foreach product which will get buyed.

In the foreach(var product in products) {} i will add this:

qrCodeImage.Save("D:\\images\\qr-Code.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                Image imgqr = Image.GetInstance("D:\\images\\qr-Code.jpeg");

to safe my qr-local, before in the foreach, will generate a new qrcode, so i will get different ones.


Later on, in the foreach, i will add this code to get the qr-code on the pdf-invoice:

var qrimage = Image.GetInstance("D:\\images\\qr-Code.jpeg");
                qrimage.Alignment = GetAlignment(lang, true);
                qrimage.ScaleToFit(65f, 65f);
                var cellqrcode = new PdfPCell { Border = Rectangle.NO_BORDER };
                cellqrcode.AddElement(qrimage);
                productTable.AddCell(cellqrcode);





Is this the right way to add a image for every product?
3 years ago
I tried this, I published the website, but I can't see there are changes at the pdf invoice, and I can't find the qr code.
3 years ago
KletterturmWeizenkirchen wrote:
I tried this, I published the website, but I can't see there are changes at the pdf invoice, and I can't find the qr code.

Not sure what version of nop your trying to rework the pdfservice. Nop4.3 uses ITextSharp for building the invoice and packingslips for orders. Your concept and additions of trying to make default nop pdf services add an image is going to be re-writting or altering the default methods. The defaults are primarily designed for developers to override the defaults with plugins when the defaults are not sufficient or drastic code alterations are needed.
Libraries/Services/Common/pdfService.cs
Write a method to retrieve your images similar to the logo image functionality and inject them in the ITextSharp functions that build the pdf document.
There are a couple of plugins out there that may let you do something without the massive default code modifications.
3 years ago
Thank you for your replies!


I finally made it. I was editing the wrong method.
I just change the SKU field for every product and there i placed the qr code!
3 years ago
KletterturmWeizenkirchen wrote:
I just change the SKU field for every product and there i placed the qr code!


In your other related post, you said "if a user purchases  the same product twice, he will get two different QR-Codes for it."  Thus, the product's SKU is not the place to store the QR code.  See that post for my comments about OrderItem/GenericAttribute.


(P.S.  You don't seem to be selecting the correct Forum for your topics.  If in doubt, and it's a development issue, then just use the "Development" forum :)
3 years ago
I am sorry that I used the wrong forum.


I don't save the QR-Codes in the SKU column, I just changed the SKU column Into a QR-codeColumn.

The QR Code gets generated in the PDF invoice .cs file, but after generating the code, I need to safe the QR-Codes in the Database, so I can get the data with an API
3 years ago
RE:  "changed the SKU column Into a QR-codeColumn"
I understand now: You are just displaying the QR code in the column where SKU was showing before.

RE: "The QR Code gets generated in the PDF invoice .cs file"
As per my other post, I think it would be best to generate the QR code in the OrderPaid event.  (Because if you later change your mind to show the QR Code in the customer's order page, and not even generate a PDF Invoice, then you won't have to re-implement it.  Not to mention that [S]OLID' s "Single Responsibility" states that a class should have one single thing to do ;)
3 years ago
 
private Order order;

public void SetQrCode(OrderPaidEvent orderPaidEvent, OrderService orderService, GenericAttributeService genericAttributeService)
        {
            var orderId = orderPaidEvent.Order.Id;
            var customerId = orderPaidEvent.Order.CustomerId;
            IList<OrderItem> orderedItems = orderService.GetOrderItems(orderId);
            foreach (var item in orderedItems)
            {
                DateTime expirationDate = DateTime.Now;
                if (item.Id == 12)
                {
                    expirationDate = expirationDate.AddDays(356);
                }


                genericAttributeService.SaveAttribute(order, "123456", expirationDate, customerId);
            }
        }



If I use this method in a new plugin, i will save the every order with a QR-Code in the genericAttribute table
I want to set the column values like that:
"Keygroup" = Order
"Key" = QrCode
"Value" = expiration date, so when the qrcode will be expired
"EntityId" = customerId


will I insert the data like I want to, if I use my method?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.