Nitesh Verma
Nitesh Verma

Reputation: 1815

How to re-size the text generated by Barbecue API?

I am trying to generate a barcode using the Barbecue API. The problem i am facing is that while i try to re-size the barcode the code in textual form which is printed below the barcode remains the same size. I need to decrease its side also. I have tried the following code :

Part 1:Original Size Barcode

Barcode b = BarcodeFactory.create2of7("4561");
b.setBarHeight(5);
b.setBarWidth(1);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(b);
if (job.printDialog())
{
        job.print();
}

Part 2: Code for resizing

Barcode b = BarcodeFactory.create2of7("4561");
b.setBarHeight(5);
b.setBarWidth(1);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(b);
if (job.printDialog())
{
job.print();
}

Below is the output image of the barcode:

Output of both the parts

As you can see the code remains the same size. How can i decrease its size? Please help me out.

Thanks.

Upvotes: 3

Views: 3883

Answers (5)

coder247
coder247

Reputation: 2943

I tried this and it worked:

    Barcode barcode;
    barcode = BarcodeFactory.createCode128B(Integer.toString("my barcode"));
    barcode.setBarHeight(40);
    barcode.setBarWidth(2);
    barcode.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));

Upvotes: 0

FPGA warrior
FPGA warrior

Reputation: 241

Since net.sourceforge.barbecue.Barcode's getFont() return a good old null, you either have to construct a Font object, or get one from somewhere, and change its size to your liking, then assign it to the Barcode with .setFont().

It works for me with this code:

Graphics2D g2d = (Graphics2D) graphics;
Barcode b = BarcodeFactory.createCode128("Hello");
Font deriveFont = g2d.getFont().deriveFont(8.5f); //copy of original Font with given size
b.setFont(deriveFont);

The Font size is not given in pixels! I believe its dimension is points.

Upvotes: 0

testTechie
testTechie

Reputation: 41

Barcode b;

b.setFont(null);

This would help you get the font size to 0.

Upvotes: 1

Atorich
Atorich

Reputation: 1

I suppose, you should to use Barcode.setFont() method to set the font size

reference

Upvotes: 0

Jayashri
Jayashri

Reputation: 366

Use class BarCodeBuilder instead if Barcode just like

  BarCodeBuilder b=new BarCodeBuilder();
  b.setCodeText("abc123");
  b.setSymbologyType(Symbology.Codabar);
  b.setResolution(new Resolution(50f,40f,ResolutionMode.Graphics));

It works for me...

Upvotes: 0

Related Questions