[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

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

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,
0
RGuillermo
Asked:
RGuillermo
  • 2
2 Solutions
 
hjgodeCommented:
hello

normally you should be able to use the same code but keep in mind that the best resolution is 1/1440 of an inch (so named twips). The twips resolution is the finest grain you can get but the real resolution depends on the printer.
Normally such label printers have a resoultion of, say 203dpi that is a 0.0125 millimeters grid.
As drivers, the graphics context and the printer itself interpolate positions given in millimeter, you may not hit an exact point (depending on what we call 'exact') when you specify a point outside the grid (or native resolution).

The internal twips resolution had a nice side effect in the past when you try to print on a large paper, it just was impossible.
The highest precision you can get is with typesetter postscript printer drivers. But even there you have to live with the millimeter-to-inch conversion.

So, you normally will not get an 1/10mm exactness with your print on a low-res printer.
0
 
hjgodeCommented:
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.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
aikimark did a good thing. VB.NET and VB classic are not the same thing. Twips were used in VB classic. They are no longer used in .NET. .NET works with pixels by default, but you can change things so that the translation between pixels and other units is done automatically for you.

Since you changed the PageUnit to millimeters, there should be no problem working with millimeters with the code you have, as long as the coordinates are correct. You might have to play a bit (or a lot) with the coordinates before you get the results you want.

You should not have to worry about the printer you use (except maybe if you still use dot matrix printers), because 14mm is the same, no matter what printer you use. Normally, unless you have a very special printer, the translation between your code coordinates and the way the printer sees thing should be done by the printer driver.

Forget about 10th of millimeter however, it is not supported.
0
 
RGuillermoProject ManagerAuthor Commented:
Thank you very much!! sorry for the delay I had to travel for work.!
Thanks again!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now