Jump to content

Barcode Printing in AU3


ptrex
 Share

Recommended Posts

Barcode Printing in AU3

Some time ago I needed to print some Barcode.

Therefore I did a little research together with my friend Google.

This is what seems the easiest way to get the job done :

- Use PostScript code to generate the barcode.

- Download PrintFile to to handle the Printjob of the PostScript code : Printfile Tool

- IMORTANT Put a copy of the "prfile32.exe" in the scriptfolder and run it.

- Use AU3 to glue it together and make a nice GUI (if you want)

Barcode Sample

Barcode_Printer_Sample.au3

Image Sample

Image Printer Sample.au3

For those of you who don't know what PostScript is :

Postscript is a programming language that was designed to specify the layout of the printed page. Postscript printers and postscript display software use an interpreter to convert the page description into the displayed graphics.

A good start learning some basics is here : PS Tutorial

In order to print the script you need to print it to PostScript printer.

But for those of you who don't have a PS printer. No worries, you can print it to a PDF printer to !!

Needles to say of course is that PS scripts are 100% compatible with PDF.

Since PostScript was developed by Adobe !!

This results in a nice side effect of this script.

Meaning that when runnng PS commands, you can create your own PDF documents as well.

Therefor I added some nice examples on how to, in the PS script example.

Give it a try and print it to a PDF printer.

(If you don"t have one, PDFCreator is a good one, see my signature somewhere)

Added a EAN13 checksum calculator

Dim $BarCode ; = "544900000043"
Dim $length
Dim $Odd, $Even, $CheckSum

; Initialize Vars
$Odd = 0
$Even = 0
$CheckSum = 0

$BarCode = InputBox("EAN13 CheckSum", "Enter 12 Digit Barcode Value", "")

$length = StringLen($BarCode)

If mod($length,2) <> 0 Then
        MsgBox(0,"Error " ,"Not a correct number of digits entered !! ")
        Exit
    Elseif int($length) <> 12 Then
        MsgBox(0,"Error " ,"Not a correct number of digits entered !! ")
        Exit
Else

    ; Calculate the Odd values
    For $i = 1 to $length Step 2
        $Odd = $Odd + (int(StringMid($BarCode,$i,1)) * 1)
    Next

    ; Calculate the Even values
    For $i = 2 to $length Step 2
        $Even = $Even + (int(StringMid($BarCode,$i,1)) * 3)
    Next

; Process result
    $Result = $Odd + $Even
    $CheckSum = 10 - mod($Result, 10)
    
    If $CheckSum = 10 Then
        $CheckSum = 0
    EndIf
        MsgBox(0,"EAN Barcode Checksum",$barcode&$CheckSum )
EndIf

Enjoy !!

regards

Edited by ptrex
Link to comment
Share on other sites

  • 3 years later...

hi guy i have a question i use your Barcode_Printer_Sample.au3 ( is very best )

but i have little problem when i print i use in printer only a4 and the program have margin for letter (i suppose) how is possible change the paper format ?? thankzzz

Link to comment
Share on other sites

"/PageSize [595 842]"?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

hi insert pagesize here

$PS = '%!PS-Adobe-2.0'

$PS = $PS & @CRLF & '% --BEGIN TEMPLATE--'

$PS = $PS & @CRLF

$PS = $PS & @CRLF & '% --BEGIN ENCODER ean13--'

$PS = $PS & @CRLF & '% --DESC: EAN-13'

$PS = $PS & @CRLF & '% --EXAM: 977147396801'

$PS = $PS & @CRLF & '% --EXOP: includetext guardwhitespace'

$PS = $PS & @CRLF & '% --RNDR: renlinear'

$PS = $PS & @CRLF & '/ean13 {'

$PS = $PS & @CRLF

$PS = $PS & @CRLF & ' 0 begin'

$PS = $PS & @CRLF & '/PageSize [297 420]'

but don go print blank page :)

Link to comment
Share on other sites

@faustf

By my knowledge you don't specify any page size in EPS.

http://ds.dial.pipex.com/quite/eps1.htm

The PostScript in an EPS has to follow certain rules. For instance, it shouldn't erase the page since that would affect the whole page, not just its own part. Another forbidden thing is selecting a page size,

because this would both change the size of, and erase, the whole page.

Where to print has to be calculated, starting from the 0,0 coordinates.

The units for the graphical operations are measured in points, with 72 points per inch.

The PostScript coordinate system defines the 0 0 position to be at the lower left corner of the page,

so 72 72 is one inch from the left, and one inch up from the bottom. For a standard 8.5x11" letter-sized sheet of paper,

the upper right corner is therefore 612 792.

An A4 is W 21 x H 29.7 cm or 8.26771654 x 11.6929134 inches = W = 595,27559088 Units x H = 841,8897648 Units

Rgds,

ptrex

Link to comment
Share on other sites

  • 1 month later...

hi guy i have a little problem i want insert a variable X and Y in place of dim $di = '20 750 moveto'

how can do ?? i tryed in this mode but dont go dim $di = ''&$x&$y&' moveto' and dim $di = ''&$x&''&$y&' moveto'

but dont go :oops:

Link to comment
Share on other sites

  • 2 months later...

I work with barcodes professionally, it is a much more complex topic than just EAN13.

Just thought I would mention this resource, since it has not been linked in the thread:

http://code.google.com/p/postscriptbarcode/

It can't make all barcodes, but most of the common and then some. Perhaps useful to some people.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • 1 year later...
  • Moderators

automaker332,

We do not accept adverts for payware apps here. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...