Jump to content



Photo

Barcode - UDF


  • Please log in to reply
12 replies to this topic

#1 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 01 June 2012 - 05:57 PM

OPENBARCODES project
http://grandzebu.net/index.php?page=/informatique/codbar-en/codbar.htm
all is under GPL - GNU license , open source and completely free...

I translated original Pascal functions to PowerBuilder syntax which is very similar to AutoIt (BARCODE_powerbuilder.zip).

Now I translated all barcode functions to AutoIt syntax (barcode_autoit.zip).
BarCode UDF + example --> you must install aproppriate TTF fonts into Windows first.
barcode.au3 barcode_test.au3 print.au3 code128.ttf code25I.ttf code39.ttf ean13.ttf


Available functions:
barcode_128() barcode_ean8() barcode_ean13() barcode_25i() barcode_39()


AutoIt         
; TTF fonts must be installed in system first #AutoIt3Wrapper_run_obfuscator=y #Obfuscator_parameters=/so #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <print.au3> #include <barcode.au3> $barcode_test = GUICreate("BarCode Test", 601, 174, -1, -1) GUICtrlCreateLabel("Input:", 11, 10, 30, 17) $Input = GUICtrlCreateInput("", 41, 8, 120, 21) GUICtrlCreateLabel("Output:", 171, 10, 38, 17) $Output = GUICtrlCreateInput("", 209, 8, 120, 21) GUICtrlSetState(-1, $GUI_DISABLE) $print = GUICtrlCreateButton("Print", 340, 7, 39, 23) GUICtrlCreateLabel("Type:", 387, 10, 28, 17) $type = GUICtrlCreateCombo("", 417, 8, 91, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Code 128|EAN 8|EAN 13|Code 2 of 5 i|Code 3 of 9", "Code 128") GUICtrlCreateLabel("Size:", 517, 10, 25, 17) $size = GUICtrlCreateCombo("", 543, 8, 47, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "12|18|24|36|48|60|72", "48") $barcode = GUICtrlCreateLabel("", 10, 39, 580, 130) GUICtrlSetFont(-1, 48, 400, 0, "Code 128") GUICtrlSetBkColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE             Exit         Case $type             ChangeFont()             ApplyBarcode()         Case $size             ChangeFont()         Case $print             Print()     EndSwitch WEnd Func WM_COMMAND($hWinHandle, $iMsg, $wParam, $lParam)     If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $Input Then         ApplyBarcode()     EndIf EndFunc Func ChangeFont()     Switch GUICtrlRead($type)         Case 'Code 128'             $font_name = 'Code 128'         Case 'EAN 8','EAN 13'             $font_name = 'Code EAN13'         Case 'Code 2 of 5 i'             $font_name = 'Code 2 of 5 interleaved'         Case 'Code 3 of 9'             $font_name = 'Code 3 de 9'     EndSwitch     GUICtrlSetFont($barcode, GUICtrlRead($size), 400, 0, $font_name) EndFunc Func ApplyBarcode()     Switch GUICtrlRead($type)         Case 'Code 128'             $barcode_data = barcode_128(GUICtrlRead($Input))         Case 'EAN 8'             $barcode_data = barcode_ean8(GUICtrlRead($Input))         Case 'EAN 13'             $barcode_data = barcode_ean13(GUICtrlRead($Input))         Case 'Code 2 of 5 i'             $barcode_data = barcode_25i(GUICtrlRead($Input))         Case 'Code 3 of 9'             $barcode_data = barcode_39(GUICtrlRead($Input))     EndSwitch     GUICtrlSetData($Output, $barcode_data)     GUICtrlSetData($barcode, $barcode_data) EndFunc ; print given text on default printer in given size by all available barcode types Func Print()     $sPrinter = _GetDefaultPrinter()     If $sPrinter = "" Then Return     $hPrintDC = _WinAPI_CreateDC("winspool", $sPrinter)     _InitPrinter($hPrintDC, "Printing Barcodes from AutoIt") ; print job name     $hFont = _CreateFont_Simple('Arial', 12, $FW_BOLD)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 500, 'Input data: ' & GUICtrlRead($Input), 0xFF0000)     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Courier', 10, $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _WinAPI_SetTextColor($hPrintDC, 0x000000)     _TextOut_Centered($hPrintDC, 1400, 'Code 128')     _TextOut_Centered($hPrintDC, 2400, 'EAN 8')     _TextOut_Centered($hPrintDC, 3400, 'EAN 13')     _TextOut_Centered($hPrintDC, 4400, 'Code 2 of 5 i')     _TextOut_Centered($hPrintDC, 5400, 'Code 3 of 9')     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Code 128', GUICtrlRead($size), $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 1500, barcode_128(GUICtrlRead($Input)))     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Code EAN13', GUICtrlRead($size), $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 2500, barcode_ean8(GUICtrlRead($Input)))     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Code EAN13', GUICtrlRead($size), $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 3500, barcode_ean13(GUICtrlRead($Input)))     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Code 2 of 5 interleaved', GUICtrlRead($size), $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 4500, barcode_25i(GUICtrlRead($Input)))     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     $hFont = _CreateFont_Simple('Code 3 de 9', GUICtrlRead($size), $FW_NORMAL)     $hFontOld = _WinAPI_SelectObject($hPrintDC, $hFont)     _TextOut_Centered($hPrintDC, 5500, barcode_39(GUICtrlRead($Input)))     _WinAPI_SelectObject($hPrintDC, $hFontOld)     _WinAPI_DeleteObject($hFont)     _DeInitPrinter($hPrintDC) EndFunc


History:
2012-06-01 - only Code 128 translated
2012-06-03 - all functions translated
2012-06-04 - added Print + some inner optimizations

Original idea comes from this topic:
http://www.autoitscript.com/forum/topic/...de128b-and-printing-with-print

Previous downloads (AutoIt): 31

Attached Thumbnails

  • barcode_test.png

Attached Files


Edited by Zedna, 04 June 2012 - 09:51 PM.

  • JScript likes this





#2 JScript

JScript

    Goodbye everybody, I got tired of this system adopted here!

  • Active Members
  • PipPipPipPipPipPip
  • 1,062 posts

Posted 01 June 2012 - 07:15 PM

That was all I needed to add in a project of my electronics garage! ;)
Thanks Zedna.

Regards,

João Carlos.
http://notebook.forumais.com (Forum Maintenance Notebooks and Desktop)http://autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

Posted Image Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!       


#3 autoall

autoall

    Seeker

  • Active Members
  • 21 posts

Posted 02 June 2012 - 01:58 PM

Great work!

#4 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 03 June 2012 - 09:53 PM

New version:
- all functions translated to AutoIt

Available functions:
barcode_128() barcode_ean8() barcode_ean13() barcode_25i() barcode_39()

See first post.

Edited by Zedna, 03 June 2012 - 09:54 PM.


#5 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 04 June 2012 - 09:50 PM

New version:

2012-06-04 - added Print + some inner optimizations

EDIT:
I tested it also with Barcode scanner in my work (only Code 128)
and it seems there is some problem on Windows7 64bit in GUI with font.
There are 3 bars at begin which shouldn't be there.
So when I do Screenshot of GUI with barcode on label and print this screenshot then scanner can't read it.

But when I print it by TextOut API (see Print() in my example) with the same font and the same data value
then output barcode on printer/paper is OK and can be read by scanner.
At home on my WindowsXP this bug doesn't occur.

So it may be some bug in TTF font on 64bit systems
or it can be bug in AutoIt in GUICtrlSetFont() only on 64bit systems
or it can be bug in AutoIt in GUICtrlSetData() only on 64bit systems
or something else ...

I will do more tests of this bug later.

Edited by Zedna, 04 June 2012 - 10:13 PM.


#6 Alexisss

Alexisss

    Seeker

  • Normal Members
  • 2 posts

Posted 05 September 2012 - 03:23 PM

i am trying to print with a zebra lp2824 printer, but when i press print button, it just print an empty label. but using a normal printer, it print a complete A4 page with the input entered and the respective barcode.


what could i do to print just the barcode on the zebra lp2824 printer.??

thank you!!!

@zedna
Zedna


Edited by Alexisss, 05 September 2012 - 03:24 PM.


#7 llewxam

llewxam

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 345 posts

Posted 06 September 2012 - 05:23 AM

Just my 2 pence - I dislike barcode fonts and prefer to manually code them. Attached is how I devised Code39 by using Wiki's table "Code Details", which saved me a huge amount of work. AFAIK there is no "limitation" to how long a Code39 can be, I capped it in my script to 16 characters because I use _ScreenCapture_CaptureWnd to grab a JPG which is used on address label sheets, so if anyone re-uses this make sure those dimensions will work for you.

Enjoy
Ian


PS @ Alexisss:
What happens if you try to print anything at all to the Zebra? Will it print plain text from Notepad? I've fixed plenty of Zebras but have never owned one to experiment.

Attached Files


  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized siteagent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.

#8 Alexisss

Alexisss

    Seeker

  • Normal Members
  • 2 posts

Posted 06 September 2012 - 06:28 AM

PS @ Alexisss:
What happens if you try to print anything at all to the Zebra? Will it print plain text from Notepad? I've fixed plenty of Zebras but have never owned one to experiment.
i just try to print a text plain from note pad, so it print a blank label!!!!


there is noy way to modify the barcode udr to print on a zebra printer??, i am using a 2 inch per 1 inch label

#9 FireFox

FireFox

    Liar using Chrome :>

  • Active Members
  • PipPipPipPipPipPip
  • 3,173 posts

Posted 06 September 2012 - 11:46 AM

Nice UDF, 5*

Br, FireFox.
OS : Win XP SP3 / Win 7 SP1 / Win 8 | Autoit version: latest stable / beta

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | What you've done today | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 22 April, 2013 - If you find dead links please send me a PM, do not post in the topics !

#10 Jemboy

Jemboy

    Seeker

  • Normal Members
  • 4 posts

Posted 27 March 2013 - 08:36 PM

Hi Zedna,

I succesfully converted your example to print text and barcodes on a label(printer).
However for every new labelsize, I need to manually change the default papersize (via Printerproberties, General Tab, Preferences)
to print correctly.
I have analyzed your print.au3 and search with Google to find a way to send the papersize automatically before printing the label,
however I am over my head with DLLs and commands like DLLStructdata .

Could you (or other forummembers) help me out with changing the papersize (and printing orientation) ?

TIA, Jemboy

#11 FireFox

FireFox

    Liar using Chrome :>

  • Active Members
  • PipPipPipPipPipPip
  • 3,173 posts

Posted 27 March 2013 - 09:36 PM

Hi,
Have you tried to change the size value at the line 84 (from print.au3) ?
DllStructSetData($tDOCINFO, "Size", 20)


Br, FireFox.

Edited by FireFox, 27 March 2013 - 09:37 PM.

OS : Win XP SP3 / Win 7 SP1 / Win 8 | Autoit version: latest stable / beta

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | What you've done today | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 22 April, 2013 - If you find dead links please send me a PM, do not post in the topics !

#12 Jemboy

Jemboy

    Seeker

  • Normal Members
  • 4 posts

Posted 28 March 2013 - 10:45 AM

Hi FireFox thanks for helping me find a solution.

I know "assumption is the mother of all f**kups", but I assume this size is more the size of the $tDOCINFO- "record" used (like a memory reservation.)
If it has something to do with the papersize, I think it's overwritten by the default papersize, input at the properties/preference of the Windows printer.
Also the value "20" isn't documented, is it A4, Letter size?

I have to little knowledge of DLL-archicture (shiver) to find find out.

#13 FireFox

FireFox

    Liar using Chrome :>

  • Active Members
  • PipPipPipPipPipPip
  • 3,173 posts

Posted 28 March 2013 - 01:24 PM

Well then you can't set it with the current UDF functions.

Edit: Have you tried to automate the "change paper size" part ?

Edited by FireFox, 28 March 2013 - 01:25 PM.

OS : Win XP SP3 / Win 7 SP1 / Win 8 | Autoit version: latest stable / beta

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | What you've done today | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 22 April, 2013 - If you find dead links please send me a PM, do not post in the topics !




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users