Jump to content


Photo

Barcode generation for datamatrix, datamatrixrectangle, code128, pdf417


  • Please log in to reply
13 replies to this topic

#1 Jesse Barnum  master

Jesse Barnum
  • 360Works
  • 392 posts
  • LocationAtlanta, GA
  • FM Client:12 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Expert
  • Certification:7, 8, 9, 10, 11
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 5d 8h 53m 52s

Posted 15 July 2011 - 08:39 AM

This is a ScriptMaster module sent in by Benjamin Brittain. It generates bar codes using the barcode4j library from Krysalis. This only demonstrates 4 bar code types, but there are many more supported by this library.

===Input Variables===
barcode_contents=07g129091pe01
type=datamatrixrectangle
size=10

===Jar Files===
Barcode4j.jar (268.1k) Barcodes <http://sourceforge.net/projects/barcode4j/files/barcode4j/>

===Notes===


===Script===
import org.krysalis.barcode4j.impl.datamatrix.DataMatrixBean
import org.krysalis.barcode4j.impl.code128.Code128Bean
import org.krysalis.barcode4j.impl.pdf417.PDF417Bean
import org.krysalis.barcode4j.output.java2d.Java2DCanvasProvider
import org.krysalis.barcode4j.impl.datamatrix.SymbolShapeHint

import java.awt.*
import java.awt.image.*

if (type == 'datamatrixrectangle'){
DataMatrixBean bean = new DataMatrixBean();
bean.setModuleWidth(Integer.parseInt(size));
bean.setShape(SymbolShapeHint.FORCE_RECTANGLE )
s = bean.calcDimensions(barcode_contents);
ss = Math.floor(s.getWidthPlusQuiet()).toInteger();
image = new BufferedImage(ss, ss, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.getGraphics();
  g2.setBackground(Color.WHITE);
  g2.clearRect(0, 0, image.getWidth(), image.getHeight());
  g2.setColor(Color.BLACK);
Java2DCanvasProvider cc = new Java2DCanvasProvider(g2, 0);
bean.generateBarcode(cc, barcode_contents);
}

if (type == 'datamatrix'){
DataMatrixBean bean = new DataMatrixBean();
bean.setModuleWidth(Integer.parseInt(size));
bean.setShape(SymbolShapeHint.FORCE_SQUARE )
s = bean.calcDimensions(barcode_contents);
ss = Math.floor(s.getWidthPlusQuiet()).toInteger();
image = new BufferedImage(ss, ss, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.getGraphics();
  g2.setBackground(Color.WHITE);
  g2.clearRect(0, 0, image.getWidth(), image.getHeight());
  g2.setColor(Color.BLACK);
Java2DCanvasProvider cc = new Java2DCanvasProvider(g2, 0);
bean.generateBarcode(cc, barcode_contents);
}

if (type == 'code128'){
Code128Bean bean = new Code128Bean()
bean.setModuleWidth(2);
bean.doQuietZone(false)
bb = Integer.parseInt(size)
bean.setBarHeight(bb)
s = bean.calcDimensions(barcode_contents)
zz =  Math.ceil(s.getWidthPlusQuiet()).toInteger()
ss = Math.floor(s.getWidthPlusQuiet()).toInteger()
image = new BufferedImage(ss , bb, BufferedImage.TYPE_INT_RGB)
Graphics2D g2 = image.getGraphics()
  g2.setBackground(Color.WHITE);
  g2.clearRect(0, 0, image.getWidth(), image.getHeight());
  g2.setColor(Color.BLACK);
Java2DCanvasProvider cc = new Java2DCanvasProvider(g2, 0)
bean.generateBarcode(cc, barcode_contents)
}

if (type == 'pdf417'){
PDF417Bean bean = new PDF417Bean();
bean.setModuleWidth(2);
bean.doQuietZone(false)
bean.setBarHeight(Integer.parseInt(size));
s = bean.calcDimensions(barcode_contents)
zz =  Math.ceil(s.getWidthPlusQuiet()).toInteger()
ss = Math.floor(s.getWidthPlusQuiet()).toInteger()
image = new BufferedImage(ss , ss, BufferedImage.TYPE_INT_RGB)
Graphics2D g2 = image.getGraphics()
  g2.setBackground(Color.WHITE);
  g2.clearRect(0, 0, image.getWidth(), image.getHeight());
  g2.setColor(Color.BLACK);
Java2DCanvasProvider cc = new Java2DCanvasProvider(g2, 0)
bean.generateBarcode(cc, barcode_contents)
}

return image;

  • 0
--Jesse Barnum, President, 360Works
http://www.360works.com
(770) 234-9293

#2 john renfrew  enthusiast, with a bit of geek

john renfrew
  • Members
  • 352 posts
  • LocationUK
  • FM Client:12 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 9d 9h 4m 52s

Posted 18 July 2011 - 06:41 AM

You probably want to add the copyright notice to that as it is copied straight out of the example file (including the double space after the equals after the zz)

and here is the code to do a Code39 in addition, but with the addition of control over bar height & size, and also the font that the numbers are written in under the code

/*
 * Copyright 2004 Jeremias Maerki.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.krysalis.barcode4j.impl.code39.Code39Bean

if (type == 'code39'){
bean = new Code39Bean()
bean.setModuleWidth(2)
bean.doQuietZone(false)
// font height
dd = 24
//bar height
bb = 80
bean.setBarHeight(bb)
// change to suit
bean.setFontName("Calibri")
bean.setFontSize(dd)
s = bean.calcDimensions(barcode_contents)
zz =  Math.ceil(s.getWidthPlusQuiet()).toInteger()
ss = Math.floor(s.getWidthPlusQuiet()).toInteger()
image = new BufferedImage(ss , bb + dd, BufferedImage.TYPE_INT_RGB)
Graphics2D g2 = image.getGraphics()
  g2.setBackground(Color.WHITE)
  g2.clearRect(0, 0, image.getWidth(), image.getHeight())
  g2.setColor(Color.BLACK)
cc = new Java2DCanvasProvider(g2, 0)
bean.generateBarcode(cc, barcode_contents.toUpperCase())
}

  • -1

#3 BBrittain  newbie

BBrittain
  • Newbies
  • Pip
  • 1 posts
  • Skill Level:Intermediate

Posted 06 August 2011 - 10:58 AM

ergh... yea that should be completely included!
It wasn't completely copied, but it certainly was used as a basis.
(I didn't know that this was going to be shown to anybody... even so, it should still be in the file)
  • 0

#4 Jeroen Aarts  newbie

Jeroen Aarts
  • Newbies
  • PipPipPip
  • 3 posts

Posted 25 January 2012 - 08:20 AM

This is extremely useful. It allows me to generate all necessary and complex barcodes, including PDF417 and EAN-13, just from 1 plugin. Thanks Benjamin (and, of course, Jesse). If anyone - like me - has difficulty creating EAN-13 barcodes and not getting the printed numbers below the barcode, using the sample code provided by Jesse: don't forget to add the font size to the bar height in order to calculate the canvas height, otherwise the printed numbers are clipsed.

Use for example this code to generate EAN-13 barcodes:


import org.krysalis.barcode4j.impl.upcean.EAN13Bean

if (type == 'ean13'){
//Create the barcode bean
  EAN13Bean bean = new EAN13Bean();
  bean.setModuleWidth(2);
  bean.doQuietZone(false) ;
  bean.setFontSize(Double.parseDouble(fontSize)) ;
  bb = Integer.parseInt(size) ;
  bbi = bb + Integer.parseInt(fontSize) ; // add font height to bar height
  bean.setBarHeight(bb)
  s = bean.calcDimensions(barcode_contents) ;
  zz =  Math.ceil(s.getWidthPlusQuiet()).toInteger()
  ss = Math.floor(s.getWidthPlusQuiet()).toInteger()
  image = new BufferedImage(ss , bbi, BufferedImage.TYPE_INT_RGB)
  Graphics2D g2 = image.getGraphics();
  g2.setBackground(Color.WHITE);
  g2.clearRect(0, 0, image.getWidth(), image.getHeight());
  g2.setColor(Color.BLACK);
  Java2DCanvasProvider cc = new Java2DCanvasProvider(g2, 0);
  //Generate the barcode
  bean.generateBarcode(cc, barcode_contents);
}

  • 0

#5 john renfrew  enthusiast, with a bit of geek

john renfrew
  • Members
  • 352 posts
  • LocationUK
  • FM Client:12 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 9d 9h 4m 52s

Posted 27 January 2012 - 01:36 PM

You can specify your own font too on the EAN one
e.g.
bean.doQuietZone(false)
bean.setFontName("Miso")

  • 0

#6 Jeroen Aarts  newbie

Jeroen Aarts
  • Newbies
  • PipPipPip
  • 3 posts

Posted 13 February 2012 - 06:28 AM

Barcodes work great this way. However, I wonder, as we often need to generate several hundreds of barcodes at once, if it is possible to prevent the screen from flickering on Windows. It seems to be application bound, as moving the window off-sreen, and inserting a 'Freeze Window' script step doesn't seem to help. Any suggestions are appreciated!

EDIT: I found the solution myself. Unchecking the 'Gui' option when registering the module does the trick.
  • 0

#7 capsprojectos  novice

capsprojectos
  • Members
  • 63 posts
  • FM Client:11 Advance
  • Platform:Windows 7
  • Skill Level:Entry Level
  • Time Online: 21h 23m 23s

Posted 12 March 2012 - 12:32 PM

This script should completely included in the next version of script master.

I have tested all types, and they all work well except EAN13 (from Jeroen Aarts), I’m getting an error "groovy.lang.MissingPropertyException: No such property: fontSize for class: Script1."
I did some test, adding bean.setFontSize(dd), but didn’t work either.

Thanks for sharing.
  • 0

#8 comeonfuture  newbie

comeonfuture
  • Newbies
  • Pip
  • 1 posts

Posted 12 March 2012 - 06:35 PM

:laugh2: Thanks for all the barcode4j generation code for all kinds of barcode types generation solution which help me out for the future barcode generation problem. And I recently find another barcode solution site which is Onbarcode and Onbarcode provides all kinds of barcode genration and reading solution as well as barcode4j with almost all common used barcode type. For example, .NET ASP data matrix barcode genrator I've recently used also provides details on the data matrix generation guide. Both barcode4j and Onbarcode are excellent which have their own features to meet our barcode need. God luck for all barcode developers and users!
  • 0

#9 Karsten Wolf  novice

Karsten Wolf
  • Members
  • 58 posts
  • LocationGermany
  • FM Client:10 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Intermediate
  • Time Online: 2d 17h 1m 27s

Posted 17 March 2012 - 06:06 AM

Something the code from this thread has evolved to.

Have fun.

Attached Files


  • 0

#10 james61  newbie

james61
  • Newbies
  • Pip
  • 1 posts

Posted 23 March 2012 - 01:15 AM

here is one qr code barcode generation library. have a look!
  • 0

#11 Susanna Moore  newbie

Susanna Moore
  • Newbies
  • Pip
  • 1 posts
  • FM Client:8
  • Platform:Windows XP
  • Skill Level:Entry Level
  • Certification:7
  • Membership:TechNet

Posted 29 January 2013 - 01:33 AM

From my barcoding experience, BarcodeLib.com provides the similar solutions for these barcodes generation.

 

 


  • 0

#12 john renfrew  enthusiast, with a bit of geek

john renfrew
  • Members
  • 352 posts
  • LocationUK
  • FM Client:12 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 9d 9h 4m 52s

Posted 29 January 2013 - 10:41 AM

And both those two involve cost whereas b4j is open source. Or have I missed something??


  • 0

#13 Dewar  newbie

Dewar
  • Newbies
  • PipPip
  • 2 posts
  • FM Client:7 Advance
  • Platform:Windows Vista
  • Skill Level:Entry Level
  • Certification:7
  • Membership:FIleMaker Platinum Member

Posted 15 April 2013 - 12:43 AM

Yep, see this barcode generating library in C# .net

 

 

Barcode barcode = new Barcode();
barcode.Symbology = BarcodeType.Code39;
barcode.Data = "01234567890";
barcode.Save(theImage, saveFileName, RasterImageFormat.Tif, theImage.BitsPerPixel)


  • 0

#14 afasfwew  newbie

afasfwew
  • Newbies
  • Pip
  • 1 posts
  • FM Client:5.5
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Expert
  • Certification:10
  • Membership:FileMaker Business Alliance

Posted 02 June 2013 - 11:48 PM

Yep, see this barcode generating library in C# .net

 

 

Barcode barcode = new Barcode();
barcode.Symbology = BarcodeType.Code39;
barcode.Data = "01234567890";
barcode.Save(theImage, saveFileName, RasterImageFormat.Tif, theImage.BitsPerPixel)

Thanks for sharing.


  • 0