Free Support Forum - aspose.com

Can not set Margin when AutosizeMode is Interpolation or Nearest


#1

hi,

I just download trial version of Aspose Barcode .Net, i create a fist sample by this code:

using (BarCodeGenerator generator = new BarCodeGenerator(EncodeTypes.Code128, "123456789"))
        {
            Aspose.BarCode.Generation.AutoSizeMode asm = generator.AutoSizeMode;
            generator.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Interpolation;
            generator.BarCodeWidth.Pixels = rectBounding.Width;
            generator.BarCodeHeight.Pixels = rectBounding.Height;

            generator.ForeColor = Color.Black;
            generator.CodeTextStyle.Location = CodeLocation.Below;
            generator.Margins.Bottom.Pixels = 15;
            generator.Margins.Top.Pixels = 15;

}

But no left and right margin for generated barcode. Is it a bug?
There are two classes can use to create barcode: BarcodeBuilder and BarcodeGeneration ? Wich one is the best to create barcode ?

I want to integrate your barcode sdk .net into my project so i hope you can answer my questions in the progress of evaluating its functionalities before buying.

Best regards,


#2

@hoahong

Thank you for considering Aspose.BarCode for .NET.

BarCodeGenerator class shall be used to generate barcode whereas BarCodeBuilder class is obsolete now. For generating barcode and setting margins, you may follow this link:
https://docs.aspose.com/display/barcodenet/Generating+Barcodes+using+New+Barcode+Generation+API

Moreover, please elaborate more regarding margins as we see you are setting height and width with margins and your code is working fine.


#3

Hi Muzammil,
The Margin property of BarcodeGenerator does not works with any case.
For example, with this case of code:

using (BarCodeGenerator g = new BarCodeGenerator(EncodeTypes.Code128))
        {
            g.AutoSizeMode = Aspose.BarCode.Generation.AutoSizeMode.Interpolation;
            g.Margins.Top.Millimeters = 8;
            g.Save(@"C:\test.png");
        }

Could you create a sample that works ? I want to set both Margin and Barcode width/height.

Below is the result of code above.
test.png (1.5 KB)

Best regards,


#4

@hoahong

Thank you for your feedback.

The margin properties such as Top, Bottom, Left or Right can be used to get only. These properties cannot be set. Moreover, the height and width properties shall be used to generate the barcode in a specific size.

Furthermore, please feel free to write back to us if you need additional information.


#5

Thank you so much! Muzammil

It means, you barcode sdk can not set margins ? can you ?

If it can set Margins, please create a sample for this case with BarcodeGenerator.

Best grards,


#6

@hoahong

You can set margin properties by providing unit value as you have already done in your provided code sample. However, we have investigated and found that your code sample is correct but API is not implementing margin properties correctly. So we have logged this issue with ID " BARCODENET-37095" for further investigation and you will automatically be informed here once we have more information to share.


#7

@MuzammilKhan Great hear about that! Thanks