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 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,
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 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,
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.
Thanks. I tried with symbology EAN128 and worked perfectly but with symbology Code128 and with any kind of Code128CodeSet the reading failed.
Hi Jorge,
Hi Jorge,
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.