Thread: [Gambas-user] Barcode.... Here ya go Hamilton...
Brought to you by:
gambas
From: Stephen B. <sb...@cs...> - 2007-04-27 15:59:36
|
This is the code (slightly modified from the original) for a Module (Mine is called 'BarCodeFunctions') that should do the trick for you (and anyone else who needs to make barcodes). Steve. ' Gambas module file '*********************************************************************** '* Author: Stephen Bungay. '* Date: Sept 15 2006 '* Creates a barcode PNG file using the GNU Barcode '* tool and Imagemagic convert. '* Returns a Picture object. '*********************************************************************** PUBLIC FUNCTION CreateBarCode(pEncodeString AS String, OPTIONAL pGiftCard AS Boolean, pProduction AS Boolean) AS Picture DIM ShellString AS String DIM PathString AS String DIM BarcodePathString AS String DIM ReturnValue AS Picture DIM FilePrefix AS String ' Remove any previopusly created barcode. SHELL "rm -f " & user.Home & "/Barcode-" & pEncodeString & ".png" ' This command creates a 128b barcode... ShellString = BarCodePathString & "barcode -b " & pEncodeString & " -e 128b -o " & "~/Barcode-" & pEncodeString & ".ps" SHELL ShellString WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") WAIT 0.4 WEND ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" SHELL ShellString WHILE Exist( "~/Barcode-" & pEncodeString & ".png") = FALSE WAIT 1 WEND SHELL "rm -f " & "~/Barcode-" & pEncodeString & ".ps" WAIT 0.2 ReturnValue = picture.load( "~/Barcode-" & pEncodeString & ".png") RETURN (ReturnValue) END '************************************************************************* '* Print a barcode. '* Takes a filename (PNG File created by the routine above) '* as a parameter. ' * Substutute your printer here. This one uses a '* DYMO_Labelwriter_400 '************************************************************************* PUBLIC SUB PrintBarCode(pFileName AS String) IF FormLauncher.Environment = ModuleConstants.cProduction THEN SHELL "lpr -P DYMO_LabelWriter_400_USB_1 /home/kidscopos/Barcode-" & pFileName ELSE Message.Info("Dev Environment In Use.\n" & "Printing disabled.") END IF END |
From: sbungay <sb...@cs...> - 2007-04-27 16:02:18
|
One small change to the source... the following line; SHELL "rm -f " & user.Home & "/Barcode-" & pEncodeString & ".png" should read SHELL "rm -f " & "~/Barcode-" & pEncodeString & ".png" Stephen Bungay wrote: > This is the code (slightly modified from the original) for a Module (Mine is > called 'BarCodeFunctions') that should do the trick for you (and anyone else > who needs to make barcodes). > > Steve. > > ' Gambas module file > '*********************************************************************** > '* Author: Stephen Bungay. > '* Date: Sept 15 2006 > '* Creates a barcode PNG file using the GNU Barcode > '* tool and Imagemagic convert. > '* Returns a Picture object. > '*********************************************************************** > PUBLIC FUNCTION CreateBarCode(pEncodeString AS String, OPTIONAL pGiftCard AS > Boolean, pProduction AS Boolean) AS Picture > > DIM ShellString AS String > DIM PathString AS String > DIM BarcodePathString AS String > DIM ReturnValue AS Picture > DIM FilePrefix AS String > > ' Remove any previopusly created barcode. > SHELL "rm -f " & user.Home & "/Barcode-" & pEncodeString & ".png" > > ' This command creates a 128b barcode... > ShellString = BarCodePathString & "barcode -b " & pEncodeString & " -e > 128b -o " & "~/Barcode-" & pEncodeString & ".ps" > > SHELL ShellString > > WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") > WAIT 0.4 > WEND > > ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop > 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" > > SHELL ShellString > > WHILE Exist( "~/Barcode-" & pEncodeString & ".png") = FALSE > WAIT 1 > WEND > > SHELL "rm -f " & "~/Barcode-" & pEncodeString & ".ps" > > WAIT 0.2 > > ReturnValue = picture.load( "~/Barcode-" & pEncodeString & ".png") > > RETURN (ReturnValue) > END > > '************************************************************************* > '* Print a barcode. > '* Takes a filename (PNG File created by the routine above) > '* as a parameter. > ' * Substutute your printer here. This one uses a > '* DYMO_Labelwriter_400 > '************************************************************************* > PUBLIC SUB PrintBarCode(pFileName AS String) > IF FormLauncher.Environment = ModuleConstants.cProduction THEN > SHELL "lpr -P DYMO_LabelWriter_400_USB_1 /home/kidscopos/Barcode-" & > pFileName > ELSE > Message.Info("Dev Environment In Use.\n" & > "Printing disabled.") > > END IF > > > END > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Gambas-user mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user > |
From: ron <ro...@ti...> - 2007-04-27 17:04:13
|
On Friday 27 April 2007 17:58, Stephen Bungay wrote: > =A0' This command creates a 128b barcode... > =A0 ShellString =3D BarCodePathString & "barcode -b " & pEncodeString & "= -e=20 > 128b -o " & =A0"~/Barcode-" & pEncodeString & ".ps" BarCodePathString is used and Dim but never set with path > =A0=20 > =A0 SHELL ShellString =A0 > =A0=20 > =A0 WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") > =A0 =A0 =A0 =A0 WAIT 0.4 > =A0 WEND=20 > =A0=20 > =A0 ShellString =3D "convert " & "~/Barcode-" & pEncodeString & ".ps -cro= p=20 > 205x80+7+703 " & =A0"~/Barcode-" & pEncodeString & ".png" >=20 must be ? > ShellString =3D "convert " & "~/Barcode-" & pEncodeString & ".ps -crop= =20 > " 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" =2D---^--------------^ =2Dcrop need dimensions and 205x80+7+703=3D17110 :) :) Nice weekend Ron |
From: sbungay <sb...@cs...> - 2007-04-27 17:57:16
|
Forgot to change that piece.. good call... thanks. ron wrote: > On Friday 27 April 2007 17:58, Stephen Bungay wrote: > >> ' This command creates a 128b barcode... >> ShellString = BarCodePathString & "barcode -b " & pEncodeString & " -e >>128b -o " & "~/Barcode-" & pEncodeString & ".ps" > > > BarCodePathString is used and Dim but never set with path > > >> >> SHELL ShellString >> >> WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") >> WAIT 0.4 >> WEND >> >> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop >>205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" >> > > > must be ? > >> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop >> " 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" > > ----^--------------^ > -crop need dimensions and 205x80+7+703=17110 :) :) > > > Nice weekend > > Ron > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Gambas-user mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user > |
From: Paul H. <hor...@cs...> - 2007-04-27 18:53:05
|
On April 27, 2007, sbungay wrote: > Forgot to change that piece.. good call... thanks. > > ron wrote: > > On Friday 27 April 2007 17:58, Stephen Bungay wrote: > >> ' This command creates a 128b barcode... > >> ShellString = BarCodePathString & "barcode -b " & pEncodeString & " > >> -e 128b -o " & "~/Barcode-" & pEncodeString & ".ps" > > > > BarCodePathString is used and Dim but never set with path > > > >> SHELL ShellString > >> > >> WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") > >> WAIT 0.4 > >> WEND > >> > >> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop > >>205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" > > > > must be ? > > > >> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop > >> " 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" > > > > ----^--------------^ > > -crop need dimensions and 205x80+7+703=17110 :) :) Isn't 205x80 (dimensions - width x height) and +7+703 (offsets - left down) the geometry required? I'm not sure if just supplying a single number (17110) would give the right crop location :) snip... -- Paul Horechuk Think Free Use Open Source Software |
From: sbungay <sb...@cs...> - 2007-04-27 18:54:55
|
I think you're right about that... never noticed the other part of his post... does anyone know if the single number would work? Somehow me thinks now. Paul Horechuk wrote: > On April 27, 2007, sbungay wrote: > >> Forgot to change that piece.. good call... thanks. >> >>ron wrote: >> >>>On Friday 27 April 2007 17:58, Stephen Bungay wrote: >>> >>>>' This command creates a 128b barcode... >>>> ShellString = BarCodePathString & "barcode -b " & pEncodeString & " >>>>-e 128b -o " & "~/Barcode-" & pEncodeString & ".ps" >>> >>>BarCodePathString is used and Dim but never set with path >>> >>> >>>> SHELL ShellString >>>> >>>> WHILE NOT Exist("~/Barcode-" & pEncodeString & ".ps") >>>> WAIT 0.4 >>>> WEND >>>> >>>> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop >>>>205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" >>> >>>must be ? >>> >>> >>>> ShellString = "convert " & "~/Barcode-" & pEncodeString & ".ps -crop >>>> " 205x80+7+703 " & "~/Barcode-" & pEncodeString & ".png" >>> >>>----^--------------^ >>>-crop need dimensions and 205x80+7+703=17110 :) :) > > > Isn't 205x80 (dimensions - width x height) and +7+703 (offsets - left down) > the geometry required? I'm not sure if just supplying a single number > (17110) would give the right crop location :) > > snip... > > |