Barcode and QR code often used to.
Java camp famous zxing
https://github.com/zxing/zxing
.Net has its docking port
https://github.com/micjahn/ZXing.Net
Call is simple
var qrWriter = new BarcodeWriterPixelData { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = 1000, Width = 1000, Margin = 10 } }; var pixelData = qrWriter.Write("i love you"); using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)) using (var ms = new MemoryStream()) { // lock the data area for fast access var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb); try { // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length); } finally { bitmap.UnlockBits(bitmapData); } // save to stream as PNG //bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); bitmap.Save(@"C:\keatkeat\my projects\asp.net core\2.2\html-to-pdf\Project\123.png", System.Drawing.Imaging.ImageFormat.Png); }
There are many Barcode Format, can choose their own.
Here used bitmap, is from the official website of the demo copied to.
Early core does not support the system draw, so the demo says rely CoreCompat.System.Drawing,
But then .net core introduced System.Drawing.Common so is the cross-platform.
demo : https://github.com/micjahn/ZXing.Net/tree/master/Clients/ASP.NetCoreDemo