troubleshooting Question

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

Avatar of RGuillermo
RGuillermoFlag for United States of America asked on
Visual Basic.NET.NET Programming
4 Comments2 Solutions515 ViewsLast Modified:
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

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,
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros