Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-12-17
5
Medium Priority
?
370 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:rguillermo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 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:rguillermo
ID: 40550296
Thank you very much!! sorry for the delay I had to travel for work.!
Thanks again!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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