We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Save QR barcode to file

The barcode doesn’t exist on the control list, so sorry for posting my question under a different control

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:

  • Content: The text to encode
  • Titel: A text that identifies the QR code, which I would like to have “printed” beneath the QR code. The title differs from the content.
  • Filename: The name for the file (without extension), to which the QR code should be saved.

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.


6 Replies

CM Chinnu Muniyappan Syncfusion Team September 12, 2016 09:04 AM UTC

Hi Morten, 
Thank you for contacting Syncfusion support. 
Yes, we can generate Barcode images and zip it in a single file, we have created a simple console application sample to achieve your requirement. The same code will work fine for MVC application. 
Required Assemblies: 
Syncfusion.Pdf.Base.dll 
Syncfusion.Compression.Base.dll 
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); 
 
Sample link: 

Please let us know if you have any concern. 
Regards, 
Chinnu 



AS Ankita S February 5, 2019 04:14 PM UTC

I have downloaded your console application project , gives no error, but i need to download that zip file as well. As of now, where does the zip go after images gets saved in it.

Please help asap :)

Thanks


KC Karthikeyan Chandrasekar Syncfusion Team February 6, 2019 06:55 AM UTC

Hi Ankita, 
I modified the code snippet to download the zip file from the MVC controller. 
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"); 
} 
 
Revert me back if you need any further assistance. 
Regards,            
Karthikeyan  



AA Aaron March 23, 2020 07:12 PM UTC

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?


MO Morny March 24, 2020 09:18 AM UTC

Hi Aaron
The project has been canceled due to the fact, that Android has discontinued the possibility to intercept an SMS before it reaches the preferred SMS application on the phone.
There is therefore no further need for this feature at my end.
If you want to continue with the feature, an inpmenentation in ASP.NET Core and/or ASP.NET MVC would be prefereble as I see it.

Kind Regards

Morten


SL Sowmiya Loganathan Syncfusion Team March 24, 2020 10:33 AM UTC

Hi Aaron,   
 
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.   
 
 
Regards,  
Sowmiya Loganathan  
 


Loader.
Live Chat Icon For mobile
Up arrow icon