Jump to content

  •  

Photo

Barcode generation for datamatrix, datamatrixrectangle, code128, pdf417


  • Please log in to reply
18 replies to this topic

#1 Jesse Barnum  addict

Jesse Barnum
  • 360Works
  • 474 posts
  • LocationAtlanta, GA
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Expert
  • Certification:7, 8, 9, 10, 11, 12
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 6d 1h 46m 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
  • 406 posts
  • LocationUK
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 10d 4h 25m 39s

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())
}

  • 0

#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  member

Jeroen Aarts
  • Members
  • 12 posts
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Expert
  • Certification:8, 9, 10, 11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1h 24m 4s

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
  • 406 posts
  • LocationUK
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 10d 4h 25m 39s

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  member

Jeroen Aarts
  • Members
  • 12 posts
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Expert
  • Certification:8, 9, 10, 11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance, FIleMaker Platinum Member
  • Time Online: 1h 24m 4s

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 Application:11 Advance
  • Platform:Windows 7
  • Skill Level:Beginner
  • 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
  • 68 posts
  • LocationGermany
  • FM Application:10 Advance
  • Platform:Mac OS X Snow Leopard
  • Skill Level:Intermediate
  • Time Online: 2d 21h 2m 5s

Posted 17 March 2012 - 06:06 AM

Something the code from this thread has evolved to.

Have fun.

Attached Files


  • 1

#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 Application:8
  • Platform:Windows XP
  • Skill Level:Beginner
  • 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
  • 406 posts
  • LocationUK
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 10d 4h 25m 39s

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 Application:7 Advance
  • Platform:Windows Vista
  • Skill Level:Beginner
  • 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)


  • -1

#14 afasfwew  newbie

afasfwew
  • Newbies
  • Pip
  • 1 posts
  • FM Application: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

#15 recthor  newbie

recthor
  • Newbies
  • PipPip
  • 2 posts
  • FM Application:5
  • Platform:Max OS X Tiger
  • Skill Level:Novice
  • Certification:7
  • Membership:TechNet

Posted 03 July 2013 - 01:42 AM

I think some imaging sdk  programmes can enable to quickly generate barcodes. i have use imaging sdkr which can original layouts hyperlinks, Images and tables retained in word ,text, image, Epub, html.but i forgot download the wedsite ,go to google. By the way , pay attention to your system platform, select the suitable one . I use a barcode generator driver found on the internet . Install it and it becomes a selectable option.Then you can generate barcodes  in many formats  in any program at all, including Adobe Acrobat . Just open the sdk, select barcode, and choice a form you want, then you can generate barcode in c#, vb, asp ,etc ,the task will be finished in several seconds. if you haven't found a good choice  , you can have a try. best wishes.


  • -1

#16 TrulySimple  novice

TrulySimple
  • Members
  • 30 posts
  • LocationAdelaide, South Australia
  • FM Application:12 Advance
  • Platform:Mac OS X Mountain Lion
  • Skill Level:Intermediate
  • Membership:TechNet
  • Time Online: 1h 40m 8s

Posted 19 August 2013 - 05:27 PM

Does anyone know if there is a code3of9 extended bean ( code39ext ) available to use with this script master module?


  • 0
What is wrong with right now, unless you think about it?

#17 john renfrew  enthusiast, with a bit of geek

john renfrew
  • Members
  • 406 posts
  • LocationUK
  • FM Application:13 Advance
  • Platform:Cross Platform
  • Skill Level:Intermediate
  • Certification:11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 10d 4h 25m 39s

Posted 22 August 2013 - 04:59 AM

 

the code39 bean further up the page will work with
bean.setExtendedCharSetEnabled(true)
 
 
also can me made from inside iText with a code39 barcode with
.setExtended(true)

  • 1

#18 Claus Lavendt  Expert

Claus Lavendt
  • Members
  • 174 posts
  • FM Application:13 Advance
  • Platform:Mac OS X Mavericks
  • Skill Level:Expert
  • Certification:11, 12, 13
  • Membership:TechNet, FileMaker Business Alliance
  • Time Online: 21h 30m 39s

Posted 12 September 2013 - 11:16 AM

I have code128 and pdf417 in my plugin and I am using the same jar library.

Pretty much, the only thing you need to adjust, is the reference to the code.

And if you look at Jesse's original post, you will see that these 2 codes are included.

datamatrixrectangle, is not one I know about. But go look at the jar library project website.

As I recall, they have some good documentation stuff there...


  • 1

:) Claus Lavendt

www.datamanix.com


#19 egill  newbie

egill
  • Newbies
  • Pip
  • 1 posts
  • FM Application:11 Advance
  • Platform:Mac OS 9
  • Skill Level:Intermediate

Posted 08 May 2014 - 12:51 PM

Is there any way to increase the resolution of the output image?


  • 0




FMForum Advertisers