Reduce the size of the QR Code

Hi Team,

How do we reduce the size of the QR code? I am sending the Scaling factor as 15 and it gives me an error as size can not be less than 0.
it is wokring upto 45 as the scaling factor. we need a very small qr code in our document (height of 10 mm).
Can you please help me on how to control the size of the QR code? I Have attached the CustomBarCodeGenerator file and sample template that I am using.
Appreciate you help!.
qrcodequestion.zip (9.9 KB)

Thanks
–Vijay

@vbhasker It looks like the issue is related to Aspose.Barcode, not to Aspose.Words. So I will move the topic into the appropriate forum. My colleagues from Aspose.Barcode team will help you shortly.

Sure. Thanks alexey.

@vbhasker,

I evaluated your provided code segment a bit but could not test it precisely. We appreciate if you could separate the issue regarding Aspose.BarCode API only. Please create a standalone sample console application using Aspose.BarCode for .NET v23.6 (latest version), zip the project with all resource files to reproduce the issue on our end. We will check your issue and address it accordingly.

PS. please exclude Aspose.BarCode.Dll to minimize the size of the project.

@amjad.sahi

Thanks for your reply.
I have created a console application , please find the attached zip file. you can change the scaling factor in word document that is in Data folder of the application for your testing.

QRCodeTest.zip (910.7 KB)

I have removed SkiaSharp related DLL files and Aspose.Words related dll files in this console application due to some size restrictions to upload in this forum site. can you please install those aspose words nuget package once you open the solution and same for skiasharp dlls.

Thanks
–Vijay

@vbhasker,

Thanks for the sample with resource files.

After an initial test, I am able to reproduce the issue as you mentioned by using your sample app with resource files. I found an exception “System.ArgumentException: ‘Size cannot be less than or equal to 0.’” when generating QR code image with reduced size. I simply changed the line of code to reproduce the issue:

const float scale = 1.0f; // Empiric scaling factor for converting Word barcode to Aspose.BarCode

to:

const float scale = 0.4f; // Empiric scaling factor for converting Word barcode to Aspose.BarCode

We need to investigate your issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): BARCODENET-38661

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

You can try this variant of IBarcodeGenerator
TestWordBarcodeGenerator.zip (1.3 KB)

The main problem with using IBarcodeGenerator with low size images is absence of resolution. Any raster image consists from pixels and these pixels are drawn with the selected resolution. Aspose.Words IBarcodeGenerator has hardcoded resolution 96 dpi. This leads to the situation when pixel on small images is less then 1 and barcode cannot be drawn in raster.

You can use other ways to add barcode image to word documents which allow to add resolution to embedded image.

Hi alexander,

I tried the variant provided by you by increasing resolution to 300 and was able to reduce size of qr code with scaling factor 30.
(even less scaling factor also). this was implemented with Image as the return type of barcode.
but in out application due to security reasons we can not use system.drawing dll , so we are using Skiasharp dll.
with Skiasharp.SKBitmap I am not getting same size of the image, code text is also going to next line below image.
it is little bit bigger in size also. How do we get same size image here with Skiasharp.SKBitmap.

appreciate your help.

Thanks
–Vijay

@vbhasker,

Thanks for your feedback.

We will evaluate and get back to you soon.

Hi Amjad,

Thanks for your reply!. I have attached the sample solution to replicate at your end. attached the desired output pdf also to make out the difference. dlls are removed as there are size restrictions to attach.
QRCodeTest_0707ForForum.zip (300.0 KB)
Sample_Expected_output.zip (30.6 KB)

Appreciate your help!

Thanks
–Vijay

It is impossible with current Aspose.Words API and Skiasharp.SKBitmap. It does not have resolution. Aspose.Drawing.Bitmap has resolution and it is possible to generate smaller raster image with higher resolution.

You need a request to update Aspose.Words API from Skiasharp to Aspose.Drawing.

Also article about IBarcodeGenerator

Hi @alexander.gavriluk,

Thanks for your reply!.
Could you please help me how to request Aspose.Words to update\provide Aspose.words API from Skiasharp to Aspose.Drawing.

Thanks
–Vijay

@vbhasker,

You may post in Aspose.Words forum to update APIs (if possible).

Ok you can create topic on Apose.Words forum with the following text:

IBarcodeGenerator from Apose.Words allows to create raster image in SKBitmap which does not supports resolution. This leads to the situation when low sized barcodes cannot be created because barcode element cannot be less than 1 pixel.

The situation can be solved in different ways:

  • Replace Skiasharp.SKBitmap to Aspose.Drawing.Bitmap and take attention to resolution creating low sized raster images with high details;

  • Change IBarcodeGenerator to return real image horizontal and vertical size in inches/points/millimeters with SKBitmap;

  • Change IBarcodeGenerator to return image resolution with SKBitmap.