On a website, I have a collection of items, each containing some information for a QR code, and a need for saving the QR code for each item to a separate file for download and insertion into a document in a text editor e.g. Word.
The information for the QR code is:
If possible, I would like to create and save all QR codes in a loop somewhat like this:
Foreach (item in items)
{
Generate QR code
Save QR code to file
}
I would prefer the QR code saved to an image format rather than a pdf if possible.
If all the generated files automatic could be zipped into one file afterwards for easy download for the user would be awesome.
I can render the QR code to a webpage, but not save it to a file. I’m 99% sure I’ve seen an example of it done online, but now I can’t find I again.
Can this be done, and if so please provide an example.
Syncfusion.Compression.Zip.ZipArchive zip = new Syncfusion.Compression.Zip.ZipArchive();
for(int i=0;i<10;i++)
{
//Create a new PDF QR barcode
PdfQRBarcode barcode = new PdfQRBarcode();
//Set the barcode text
barcode.Text = "the text to encode";
//Export the barcode as image
Image img = barcode.ToImage();
MemoryStream ms = new MemoryStream();
//Save the image to stream
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//Archive the image to zip
zip.AddItem("img"+i.ToString ()+".png", ms, false, FileAttributes.Normal);
}
MemoryStream outputStream = new MemoryStream();
//Save the zip file.
zip.Save(outputStream,false); |
public ActionResult DownloadQRCode()
{
Syncfusion.Compression.Zip.ZipArchive zip = new Syncfusion.Compression.Zip.ZipArchive();
for (int i = 0; i < 10; i++)
{
//Create a new PDF QR barcode
PdfQRBarcode barcode = new PdfQRBarcode();
//Set the barcode text
barcode.Text = "the text to encode";
//Export the barcode as image
Image img = barcode.ToImage();
MemoryStream ms = new MemoryStream();
//Save the image to stream
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
//Archive the image to zip
zip.AddItem("img" + i.ToString() + ".png", ms, false, FileAttributes.Normal);
}
MemoryStream outputStream = new MemoryStream();
//Save the zip file.
zip.Save(outputStream, false);
return File(outputStream.ToArray(), "application/zip", "sample.zip");
} |
the .ToImage() method doesnt appear to be valid on the PdfQRBarcode class. Im in .net core, which assemblies/libraries do I need in order to make this work? |
We can able to convert the QRBarcode as image using Syncfusion.Pdf.Imaging.net.core NuGet package. Please find the below sample which illustrates the same from below,
Kindly try the above sample in your end and let us know if you need any further assistance on this.
|