Barcode width

Is there a way to control the width of the Barcode to be generated?
I’m designing a Label with a section (with specific width) for the barcode but the barcode extends outside the borders of this section. I’m able to control the height but cannot control the width.

This is a conversion to .Net from an existing VB6 project and we were able to set the width with no problems.

Thanks,

Jorge



Hi Jorge,


Thanks for your inquiry. I would like to update you that you can also generate the bar code image using the custom width support. Please visit the documentation page here. The GetOnlyBarCodeImage method will allow you to get the exact bar code in the Bitmap format and then the GetCustomSizeBarCodeImage method will allow you to set the size of the whole picture with bar code inside. I hope this will help you. Please always try to use the latest version of Aspose.BarCode 5.5.0. You can download it from here: http://www.aspose.com/community/files/51/.net-components/aspose.barcode-for-.net/default.aspx

Please let me know in case of further assistance or questions.

Thanks for the response.

I tried resizing the picture to be 90mm x 30mm but the result is a picture of 113mm x 33mm.

Again, I need to be able to print a barcode with specific width and height into a pdf.

PLEASE ADVISE.

Here’s an example of the code I used:

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Total.lic”);

Aspose.BarCode.License barcodeLicense = new Aspose.BarCode.License();
barcodeLicense.SetLicense(“Aspose.Total.lic”);

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
pdf1.PageSetup.PageWidth = (float)(8.5 * 72);
pdf1.PageSetup.PageHeight = (float)(14 * 72);

pdf1.PageSetup.Margin.Left = (float)0.00;
pdf1.PageSetup.Margin.Top = (float)0.00;
pdf1.PageSetup.Margin.Right = (float)0.00;
pdf1.PageSetup.Margin.Bottom = (float)0.00;

Aspose.Pdf.Generator.Section section = pdf1.Sections.Add();
section.PageInfo.Margin.Left = (float)0.00;
section.PageInfo.Margin.Top = (float)0.00;
section.PageInfo.Margin.Right = (float)0.00;
section.PageInfo.Margin.Bottom = (float)0.00;

BarCodeBuilder builder = new BarCodeBuilder(“420L6T3V9”, Symbology.Code128);
builder.Code128CodeSet = Code128CodeSet.C;
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.Margins.Set(0);

Aspose.BarCode.Caption caption = new Aspose.BarCode.Caption();
caption.Text = “”;
caption.Visible = false;
builder.CaptionAbove = caption;
builder.ImageQuality = ImageQualityMode.Default;
builder.CodeLocation = CodeLocation.None;

System.Drawing.Bitmap bmp = builder.GetOnlyBarCodeImage();
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
System.Drawing.Bitmap tt = builder.GetCustomSizeBarCodeImage(new System.Drawing.Size(90, 30), false);

System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
tt.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);

imgStream.Position = 0;
Aspose.Pdf.Generator.Image paragraph = new Aspose.Pdf.Generator.Image(section);
paragraph.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.MemoryBmp;
paragraph.ImageInfo.OpenType = Aspose.Pdf.Generator.ImageOpenType.Memory;

System.IO.BinaryReader reader = new System.IO.BinaryReader(imgStream);
imgStream.Position = 0L;

paragraph.ImageInfo.MemoryData = reader.ReadBytes((int)imgStream.Length);

section.Paragraphs.Add(paragraph);

pdf1.Save(“Test.pdf”);

Hi Jorge,

Thanks for your inquiry. Your provided PDF sample contains a bar code image with the correct size. It is 90mm x 30mm. Could please let me know how you are calculating its size as 113mm x 33mm? You can verify its size by using the following source code below:

Document doc = new Document(@"C:\temp\Test.pdf");

foreach (Page page in doc.Pages)

{

MemoryStream msIn = new MemoryStream();

page.Resources.Images[1].Save(msIn);

Bitmap bitmap = new Bitmap(msIn);

int hieght = bitmap.Height;

int width = bitmap.Width;

}

Width: 340 pix which is equal to 89.958333333 mm
Height: 113 pix which is equal to 29.897916667 mm

Please let me know in case of further assistance or questions.

Thanks for the response.

I just noticed that if I print the pdf document using printing settings: Page size 8.5 x 11, and “Fit” instead of the “Actual Size” the result is barcodes with the correct size.

But if I print it using Page Size 8.5 x 14 (this is the page size I used when building the pdf) and “Actual Size” and Paper Size “Legal” then the whole picture is stretched.

I just need to understand if this is the normal/expected behavior: even though I set barcode size and page size of 8.5 x 14, when printed the barcodes shows bigger (stretched).

PLEASE ADVISE.

Thanks,

Jorge


Hi Jorge,


Thanks for the information and sorry for the delayed response. Could you please share the complete source code? We will take a closer look and guide you accordingly. It Initially seems an expected behavior as with changing page size It will adjust contents accordingly.

Below is the code I'm using: I need to create a pdf with a label with 36 mm wide and 17 mm height.

When I check the last step in the code (checking the size of the image generated) it returns incorrect size:

Width = 268 pixels = 70.908333 mm
Height = 56 pixels = 14.81 mm

Even when I print the PDF, the width of the barcode is 93 mm.

PLEASE ADVISE WHAT'S WRONG IN THE CODE. HOW CAN I MAKE TO GET A BARCODE OF 36mm x 17mm.

=============================================================

System.IO.MemoryStream memStream = new System.IO.MemoryStream();

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.lic");

Aspose.BarCode.License barcodeLicense = new Aspose.BarCode.License();
barcodeLicense.SetLicense("Aspose.Total.lic");

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

BarCodeBuilder builder = new BarCodeBuilder("420T5H2S4", Symbology.Code128);
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.Code128CodeSet = Code128CodeSet.A;
builder.ImageWidth = 36F;
builder.ImageHeight = 17F;
builder.Margins.Set(0);

Aspose.BarCode.Caption caption = new Aspose.BarCode.Caption();
caption.Text = "";
caption.Visible = false;
builder.CaptionAbove = caption;
builder.ImageQuality = ImageQualityMode.Default;
builder.CodeLocation = CodeLocation.None;
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
builder.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
System.IO.BinaryReader reader = new System.IO.BinaryReader(imgStream);
imgStream.Position = 0L;
Aspose.Pdf.Generator.Image paragraph = new Aspose.Pdf.Generator.Image();
paragraph.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.MemoryBmp;
paragraph.ImageInfo.OpenType = Aspose.Pdf.Generator.ImageOpenType.Memory;
paragraph.ImageInfo.MemoryData = reader.ReadBytes((int)imgStream.Length);
paragraph.ImageInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
Aspose.Pdf.Generator.FloatingBox box = new Aspose.Pdf.Generator.FloatingBox();
box.BoxHorizontalPositioning = Aspose.Pdf.Generator.BoxHorizontalPositioningType.Page;
box.BoxVerticalPositioning = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;
box.BoxHorizontalAlignment = Aspose.Pdf.Generator.BoxHorizontalAlignmentType.Left;
box.Paragraphs.Add(paragraph);
Aspose.Pdf.Generator.Section section = pdf1.Sections.Add();
section.Paragraphs.Add(box);
pdf1.Save(@"e:\lebiz\aa.pdf");

Aspose.Pdf.Document doc = new Document(@"e:\lebiz\aa.pdf");
foreach (Page page in doc.Pages)
{
System.IO.MemoryStream msIn = new System.IO.MemoryStream();
page.Resources.Images[1].Save(msIn);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(msIn);
int height = bitmap.Height; //returns 56 pixels = 14.81 mm
int width = bitmap.Width; //returns 268 pixels = 70.908333 mm

}


Thanks,
Jorge

Hi Jorge,

Thanks for your inquiry. Please try the following source code below:

BarCodeBuilder builder = new BarCodeBuilder(“420T5H2S4”, Symbology.Code128);

builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;

builder.Code128CodeSet = Code128CodeSet.A;

builder.Margins.Set(0);

Aspose.BarCode.Caption caption = new Aspose.BarCode.Caption();

caption.Text = "";

caption.Visible = false;

builder.CaptionAbove = caption;

builder.ImageQuality = ImageQualityMode.Default;

builder.CodeLocation = CodeLocation.None;

System.IO.MemoryStream imgStream = new System.IO.MemoryStream();

// Get Bitmap with exact barcode only

Bitmap bmp = builder.GetOnlyBarCodeImage();

//actual barcode width(134 pixel) and height (56 pixel)

//we're increasing 134 to 136 because 136 pixel = 36 mm and 64 pixel = 17 mm

// Allows to set size for whole picture with barcode inside

Bitmap tt = builder.GetCustomSizeBarCodeImage(new Size(36, 17), false);

// Save image on local

tt.Save(imgStream, ImageFormat.Bmp);

I hope, this helps. Please let me know in case of further assistance or questions.

Attached is a pdf file with a sample of the barcode generated, the barcode value is 420T5H2S4 but the scanner is having difficulties reading the barcode.

Could you please advise?


Thanks,
Jorge

Attached is the result of your code and still the barcode is not readable with a scanner (barcode 39 mm wide and 18 mm height).

Here’s the exact code I used:


System.IO.MemoryStream memStream = new System.IO.MemoryStream();

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Total.lic”);

Aspose.BarCode.License barcodeLicense = new Aspose.BarCode.License();
barcodeLicense.SetLicense(“Aspose.Total.lic”);

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

Aspose.Pdf.Generator.Section section = pdf1.Sections.Add();

BarCodeBuilder builder = new BarCodeBuilder(“420T5H2S4”, Symbology.Code128);
builder.GraphicsUnit = System.Drawing.GraphicsUnit.Millimeter;
builder.Code128CodeSet = Code128CodeSet.A;
builder.Margins.Set(0);
Aspose.BarCode.Caption caption = new Aspose.BarCode.Caption();
caption.Text = “”;
caption.Visible = false;
builder.CaptionAbove = caption;
builder.ImageQuality = ImageQualityMode.Default;
builder.CodeLocation = CodeLocation.None;
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();

System.Drawing.Bitmap bmp = builder.GetOnlyBarCodeImage();
System.Drawing.Bitmap tt = builder.GetCustomSizeBarCodeImage(new System.Drawing.Size(39, 18), false);
tt.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
Aspose.Pdf.Generator.Image imageht = new Aspose.Pdf.Generator.Image(section);
imageht.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
imageht.ImageInfo.ImageStream = imgStream;
imageht.ImageInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;

Aspose.Pdf.Generator.FloatingBox box = new Aspose.Pdf.Generator.FloatingBox();
box.BoxHorizontalPositioning = Aspose.Pdf.Generator.BoxHorizontalPositioningType.Page;
box.BoxVerticalPositioning = Aspose.Pdf.Generator.BoxVerticalPositioningType.Page;

box.Paragraphs.Add(imageht);
box.Left = 10;
box.Top = 40;

section.Paragraphs.Add(box);

pdf1.Save(memStream);


PLEASE ADVISE.

Thanks,
Jorge

Hi Jorge,


Thank you for these details. I managed to replicate the problem. Aspose.BarCode component recognizes this bar code image as "202;H5S4 instead of 420T5H2S4. This problem has been logged under ticket id BARCODENET-33597 in our issue tracking system. Your request has also been linked to this issue and you will be notified as soon as it is resolved and available for the public use. Second, It would be great if you can provide details about the scanner machine. We’re sorry for the inconvenience.

Thank you so much for the response.

We are migrating an old VB6 project to .Net; as part of this conversion is this barcode generation project.

In this label generation we create 3 barcodes on the same label but the only one with issues is this one which I guess is due to the fact it has letters instead of only numbers.

When are you expecting to fix this issue? In a matter of days, weeks or months? Problem is that we have a deadline for this project and will have to make decisions if this cannot be resolved in days.

Thank you so much for your support.

Jorge


Hi Jorge,


Well, your issue has just been reported / identified and it will take some time for our development team to further investigate the issue and provide a fix (as there are other high priority issues in the development queue). However, I have asked the responsible developer to take a look at this issue shortly. As soon as he is done with his analysis of your reported issue then we will be able to provide you an ETA.
Also, I would like to inform you that Aspose provides Priority Support and Enterprise Support plans to provide high priority support for customers. Please visit the following link to check details regarding different support options if you are interested. http://www.aspose.com/corporate/services/default.aspx

Thanks Imran. The only think I need for now is an estimate of when this could be resolved and based on that we would have to make a decision to whether to wait for the fix or find a different product/solution.

Thanks, again for your time.

Hi Jorde,

Sure, I've added my comments in our internal issue tracking system. So I'm waiting for the response of our development team. As soon as any information is shared with me, I will be more than happy to share that with you.

Thanks. I tried with symbology EAN128 and worked perfectly but with symbology Code128 and with any kind of Code128CodeSet the reading failed.

Hi Jorge,


It’s great to hear from you that EAN128 symbology is working perfectly for you. Is it feasible for you to use EAN128 instead of Code128? Second, our development team is working to analyze the problem. It needs few days. They will be able to share details after 2 or 3 days. Please spare us a bit more time. We will get back to you soon.

Hi Jorge,


Thanks for your patience. Good news for you is BARCODENET-33597 has now been resolved. Our development team is working to prepare a hotfix for your problem. We’re in communication with our development team. As soon as any possibility to send you a hotfix shared by them, I will be glad to share that with you. Please spare us a bit more time.

The issues you have found earlier (filed as BARCODENET-33597) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.