We help IT Professionals succeed at work.

Visual basic 2013 printing with precision milimeters or 10th of milimeter

509 Views
Last Modified: 2015-01-14
Hello Experts,
what is the visual basic code to print on a page just anywhere not just the normal line spacing but anywhere, cahracters and graphis...
this i can do with labels using x, y coordinates I can work with a precisiĆ³n of milimeters and even pixels. it perfect!
But now I need to do the same with A4 size pages.....

Below you will find the code for labels, I need to be able to do the same por any printer with paper A4 size.
regards
Imports System.IO
Imports STROKESCRIBELib
Public Class Form1
    Public MyFileName As String
    Dim w_pro_cod As String, w_bar_cod As String, w_pro_des As String, w_uni_pri As String, w_exp_dat As String, w_qty As String
    Dim pd As New Printing.PrintDocument

    Private Sub form1_load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim a As Integer
        pd.PrinterSettings.PrinterName = "zebra printer" '-- Uncomment this to select a specific printer.
        AddHandler pd.PrintPage, AddressOf PrintHandler

        READ_DATA_01()
        For a = 1 To Val(w_qty)
            pd.Print()
        Next a
        RemoveHandler pd.PrintPage, AddressOf PrintHandler
        End
    End Sub

    Private Sub PrintHandler(ByVal sender As Object, ByVal args As Printing.PrintPageEventArgs)
        Dim barcode = AxStrokeScribe1 'This name is assigned to the barcode ActiveX by default.'To check which name the ActiveX actually has, select the ActiveX, press Alt-Enter and look for the Design group in the Properties box.
        barcode.Alphabet = enumAlphabet.CODE128 'Change this to produce barcode of the desired type.
        barcode.CtlText = w_bar_cod 'This text will be stored in the barcode.

        Dim img As Image, x As Integer = -2, y As Integer = 0, ph As Integer = 45 '
        img = barcode.GetPictureHandle(enumFormats.EMF, 30, 10) 'Generates a barcode picture, 50x30mm.
        If barcode.Error Then
            MsgBox(barcode.ErrorDescription)
            Return
        End If

        Dim ag = args.Graphics
        Dim xx = args.PageSettings

        ag.PageUnit = GraphicsUnit.Millimeter
        ag.DrawString(Space(10) & "Botica Paradera", New Font("Arial Narrow", 8), Brushes.Black, x, y + 0.5) 'A text label near the barcode
        ag.DrawString(w_pro_des, New Font("Arial Narrow", 8), Brushes.Black, x, y + 3)
        ag.DrawString(w_exp_dat, New Font("Arial Narrow", 7), Brushes.Black, x, y + 6)
        ag.DrawString("F/ " & w_uni_pri, New Font("Arial", 12), Brushes.Black, x + 11, y + 6)
        ag.DrawImage(img, x + 1, y + 10) 'Position of the left-top corner of the barcode relatively to the left-top corner of the page (millimeters).
        ag.DrawString("*******", New Font("Arial", 9), Brushes.Black, x, y + 20)
        args.HasMorePages = False 'We print only one page each time the Button1 is pressed.
    End Sub
    Private Sub READ_DATA_01()
        Dim fields() As String, w As String
        MyFileName = "c:\tmp\barcode_label.csv"
        FileOpen(1, MyFileName, OpenMode.Input)
        w = Trim(RTrim(LineInput(1)))
        w = Trim(RTrim(LineInput(1)))
        FileClose(1)
        fields = Split(w, ",")
        w_pro_cod = fields(0)
        w_bar_cod = fields(1)
        w_pro_des = Replace(fields(2), Chr(34), "")
        w_uni_pri = fields(3)
        w_exp_dat = Replace(fields(4), Chr(34), "")
        w_qty = fields(5)
    End Sub

End Class

Open in new window


Remark; So basically we are drawing at any given position. The same effect we need on a normal printer.
is it posible to use the same code ?
Regards,
Comment
Watch Question

hjgodeTier 3 Senior Technical Support Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
hjgodeTier 3 Senior Technical Support Engineer
CERTIFIED EXPERT

Commented:
One more about the restrictions with the twips:
At the time we had the problem with it, windows internally only supported integers up to 32768 for coordinates. With 2.54cm/1440*32768 the largest coordinate was 57.79cm (and -57.79cm). So it was impossible to work with a paper size >57.79cm (as the origin is top/left and not in the center).

Just to give you an idea on extremes. The paper was able to be used with a plotter.
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
RGuillermoProject Manager

Author

Commented:
Thank you very much!! sorry for the delay I had to travel for work.!
Thanks again!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.