Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-12-17
5
Medium Priority
?
390 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,
0
Comment
Question by:RaulGM BedoyaZdP
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:hjgode
hjgode earned 1000 total points
ID: 40507577
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
 
LVL 16

Expert Comment

by:hjgode
ID: 40507590
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 40508367
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
 

Author Closing Comment

by:RaulGM BedoyaZdP
ID: 40550296
Thank you very much!! sorry for the delay I had to travel for work.!
Thanks again!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question