IronBarcode (preferred)
We want to print a QR Code in a Label with iTextSharp. We use IronBarcode to generate the Barcode. Also see: IronBarcode Tutorial
var label = new Label(Enums.Alignment.CENTER);
// label.AddText("Nr. " + index.ToString("000000"), "Verdana", 12, embedFont: true); // YEAH this works fine
var qrcode = QRCodeWriter.CreateQrCode(index.ToString(), 100);
var image = qrcode.GetInstance(); image.ScaleToFitHeight = false;
label.AddImage(image);
labelCreator.AddLabel(label);
Error:
"GeneratedBarcode" contain no defintion for "GetInstance", and there is no method who would accept an argument from typ "GeneratedBarcode".
QRCoder
Also we tried it with QRCoder / Found here: QRCoder Tutorial
var label = new Label(Enums.Alignment.CENTER);
// label.AddText("Nr. " + index.ToString("000000"), "Verdana", 12, embedFont: true); // YEAH this works fine
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(index.ToString(), QRCodeGenerator.ECCLevel.Q);
var qrCode = new Base64QRCode(qrCodeData);
var qrCodeImageAsBase64 = qrCode.GetGraphic(8);
var imageBytes = Convert.FromBase64String(qrCodeImageAsBase64);
var image = Image.GetInstance(imageBytes);
image.ScaleAbsoluteWidth(40);
image.ScaleAbsoluteHeight(40);
label.AddImage(image);
labelCreator.AddLabel(label);
Error:
"Image" contain no defintion for "GetInstance".
Other try
If we use using iTextSharp.text;
and using iTextSharp.text.pdf;
Error:
Argument "1": Convert from "iTextSharp.text.Image" to "System.IO.Stream" not possible
How we can fix this problem? Thanks for your input!
~ edit
This is our function to add the Image from label.cs
. Have a look to this project we use as basic: SharpPDFLabel.
public void AddImage(Stream img)
{
var mem = new System.IO.MemoryStream();
CopyStream(img, mem);
_images.Add(mem.GetBuffer());
}
In a second step we want to add an image to our barcode, preferred is the solution of IronBarcode.