Printing from asp.net

asp.net India
  • 15 years ago

    Hi,
    i'm a new member. I have a problem. I want to print barcodes. For that i'm using Zebra TLP 2844-Z printer. I'm giving the printers internal commands to print the code. I want to know how i can access LPT1 from ASP.NET or VB.NET. If anyone has a solution, please send me the code ASAP. I'm stuck with this problem.


    Thanx in advance

  • 15 years ago
    Its very simple . Just use CreateFile API of windows and pass As LPT1 or LPT2 as file name to that it will directely write on that port.In CreateFIle API you can pass whole string to print.
    If still facing problem then respond back i will give you whole source code on VB.NET.

    Ram Kinkar Pandey
    InfoPro Inc.
    NOIDA, India

  • 15 years ago

    Hi Ram
    I do also same requrement. Appreciate your help by providing of sample code.


    I have an ASP.NET (VB.NET) where I have to print Lables on TLP 2844 Zebra printer connected on local PC LPT1. Also I have a network printer S-600 (Zebra) where I also I need to print labels from same ASP.NET application.


    I use  EPL (eltron programming language to print barcodes and text) to print labels.


    Many thanks in advance..


    Regards,

  • 15 years ago

    Hi ram
    thank u for ur reply. i dont know about createfile API. i want to print from the client side. say the printer is connected on the client machine. i want to print from the browser. simply i want to access the client resources. is it possible in asp.net? i'm using c#. reply soon


    Thanx in advance

  • 15 years ago

    Yes you can do this by using client side scripting in Javascript.


    you have the print function of javascript which will print the content of the browser, on client side


    <script language=javascript>
    Function PrintBarCodes()
    {
    print();
    }
    </script>


    use this function it will print the content of the browser. If you want to do some other client side scripting then you can do it in javascript.


    Hope this helps.

  • 15 years ago

    Does anyone have the solution?  I have the same need as ajewahar.  Please help!

  • 15 years ago

    Ok i will provide you a code today solving the same problem.
    But you people have to select your peice of code from that as i will be giving you this from some live applications of mine


    Ram kinkar pandey
    Infopro Corporation
    NOIDA, India

  • 15 years ago

    i had the same pb , and we change from Web application to a Window Application.

    like that i found code to print directly to a printer on LPTx

    a class PrintDirect.cs

    // PrintDirect.cs

    // Shows how to write data directly to the printer using Win32 API's

    // Written 17th October 2002 By J O'Donnell - [email protected]

    // Adapted from Microsoft Support article Q298141

    // This code assumes you have a printer at share \\192.168.1.101\hpl

    using

    System;

    using

    System.Text;

    using

    System.Runtime.InteropServices;

    [

    StructLayout(LayoutKind.Sequential)]

    public

    struct DOCINFO

    {

    [

    MarshalAs(UnmanagedType.LPWStr)]

    public string pDocName;

    [

    MarshalAs(UnmanagedType.LPWStr)]

    public string pOutputFile;

    [

    MarshalAs(UnmanagedType.LPWStr)]

    public string pDataType;

    }

    public

    class PrintDirect

    {

    [

    DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long OpenPrinter(string pPrinterName, ref IntPtr phPrinter, int pDefault);

    [

    DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = false,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);

     

    [

    DllImport(

    "winspool.drv"

    , CharSet = CharSet.Unicode, ExactSpelling = true,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long StartPagePrinter(IntPtr hPrinter);

    [

    DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long WritePrinter(IntPtr hPrinter, string data, int buf, ref int pcWritten);

    [

    DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long EndPagePrinter(IntPtr hPrinter);

    [

    DllImport("winspool.drv"

    , CharSet =

    CharSet.Unicode, ExactSpelling = true,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long EndDocPrinter(IntPtr hPrinter);

    [

    DllImport(

    "winspool.drv"

    , CharSet = CharSet.Unicode, ExactSpelling = true,

    CallingConvention =

    CallingConvention.StdCall)]

    public static extern long ClosePrinter(IntPtr hPrinter);

    }

     

     

    and to use it

    public

    void Print(string printerName,string docName,string referencePiece,string designationPiece,string code)

    {

    System.

    IntPtr lhPrinter=new System.IntPtr();

    DOCINFO di = new DOCINFO();

    int pcWritten=0;

    string st1;

    di.pDocName = docName;

    di.pDataType =

    "RAW";

    //If lhPrinter is 0 then an error has occured

    try

    {

    PrintDirect.OpenPrinter(printerName, ref lhPrinter, 0);

    PrintDirect.StartDocPrinter(lhPrinter,1,ref di);

    PrintDirect.StartPagePrinter(lhPrinter);

    //"^XA^CFD^FS\n^PON^FS\n^FWN^FS\n^LH020,30^FS\n^FO0,5^A0,N,50,50^FDSTART TEST^FS\n^FO0,50^A0,N,30,30^FD\nTOFUS MAXIMUS^FS\n^PQ1\n^XZ";

    /*

    * //ZPL2

    st1 = "^XA";

    st1 += "^LH50,50";

    st1 += "^FO0,0^AF^FD"+texteHaut+"^FS";

    st1 += "^FO50,50,^BC,50";

    st1 += "^FD"+code+"^FS";

    //st1 += "";

    st1 += "^XZ";

    */

    //EPL2

    st1 =

    "\nN\n";

    st1 +=

    "A25,5,0,2,1,1,N,\""+referencePiece+"\"\n";

    st1 +=

    "A25,25,0,2,1,1,N,\""+designationPiece+"\"\n";

    st1 +=

    "B25,45,0,1E,2,3,50,B,\""+code+"\"\n";

    st1 +=

    "P1\n";

     

     

    PrintDirect.WritePrinter(lhPrinter, st1, st1.Length, ref pcWritten);

    }

    catch (Exception ex)

    {

    throw new ApplicationException(ex.Message );

    }

    PrintDirect.EndPagePrinter(lhPrinter);

    PrintDirect.EndDocPrinter(lhPrinter);

    PrintDirect.ClosePrinter(lhPrinter);

    }

     

  • 13 years ago

    Hi ram !!!

    I have the same need too: create (through data already stored in a database) and print locally a bar code from a web application developed with asp.net 2.0 and c# 2005. Could you share the code for me?? I would really appreciate any help.

    Thanks a lot in advance.

    Regards.

  • 13 years ago

    Hi Ram,

    I need Barcode printing code for ASP>NET with C#, I have textbox with number. Now I am harcoded this number into a textfile and from there i will print. The text file is in a particular format. I am using Zebra TLP 2844

    Q120,24
    q831
    rN
    S4
    D7
    ZT
    JB
    OD
    R211,0
    N
    A100,75,0,1,2,2,N,"2007-OE-56-PD"
    B45,10,0,E30,3,6,47,B,"7658103672513"
    P1











     

    this is my text file format. i need [email protected]

  • 12 years ago
    Hi Ram, I am having the same problem. After having a look at the problem it appears that it can't create the file on the clients machine, there is some kind of security issue. Could you please provide me with your code. Thanks. Salma
  • 9 years ago

    Hi.. Ram... I have same Issue... My Web Application is Hosted on Server & i want to take print of Bar Code(Label/Sticker) from Client side.

    Could you share the CODE for me?? Loking forward for any HELP.

    Thanks a lot in advance.

    Regards. Mahesh Sherkar [email protected]

  • 8 years ago

    Hi, I have a zebra printer 2746a. I am making a small c# application to print labels. I can print but you'd like to print with Windows fonts and font size to be defined by me. Unfortunately I can't do it, does anyone have an idea how this is done?

    Note: printer language EPL2.

    Thank you very much msenra

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra