Καλώς ορίσατε στο dotNETZone.gr - Σύνδεση | Εγγραφή | Βοήθεια
σε

 

Αρχική σελίδα Ιστολόγια Συζητήσεις Εκθέσεις Φωτογραφιών Αρχειοθήκες

Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

Îåêßíçóå áðü ôï ìÝëïò NasosT. Τελευταία δημοσίευση από το μέλος tolis_carpenter στις 22-04-2006, 00:35. Υπάρχουν 8 απαντήσεις.
Ταξινόμηση Δημοσιεύσεων: Προηγούμενο Επόμενο
  •  11-11-2005, 19:19 7022

    Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Θα ήθελα βοήθεια για την εκτύπωση μιάς γραμμής ελληνικών-Λατινικών χαρακτήρων σε εκτυπωτή dot matrix.

    Π.χ

    Επώνυμο-Ονομα 25/10/2005 Greek city

    επίσης πρέπει να μην γινεται form feed αλλά να περιμένει ο εκτυπωτής την επόμενη σειρά για εκτύπωση αμέσως παρακάτω

    Χρησιμοποιώ vb vs 2005

  •  12-11-2005, 04:28 7031 σε απάντηση της 7022

    Right Hug [}] Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Αυτό είχα κάνει σε VBA (in MS Access) και δουλεύει μια χαρά. Με λίγο φαντασία πιστεύω ότι θα λειτουργήσει και σε VS 2005.

     Dim intFreeFile As Integer As String, strPrinterPath as String, strText as String

     glPrinterPath = "LPT1:"
     strText = "Επώνυμο-Ονομα 25/10/2005 Greek city"

     intFreeFile = FreeFile
     Open strPrinterPath For Append As #intFreeFile
     ...

     Print #intFreeFile, strText;

     ...

     Close #intFreeFile


    while (!dead) learn();
  •  17-11-2005, 22:07 7152 σε απάντηση της 7022

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Mporeis na xrisimopoiseis kai tin pio kato clasi.
    Prepei omos an theleis na olokliroseis tin function
    ConvertWindowsToOEM437Greek(string sWindows) an theleis na tiponeis apo elinika 851 se elinika dot matrix 437

    sing System;
    using System.IO;
    using System.Runtime.InteropServices;

    namespace Framework
    {
    ///
    /// Using Win32 Functions To Send Raw Data To Printer.
    ///
    public class PrintRawData
    {
    public PrintRawData()
    {

    }

    #region Win32

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    private struct DOCINFOW
    {
    [MarshalAs(UnmanagedType.LPWStr)] public string pDocName;
    [MarshalAs(UnmanagedType.LPWStr)] public string pOutputFile;
    [MarshalAs(UnmanagedType.LPWStr)] public string pDataType;
    }


    [DllImport("winspool.drv", EntryPoint="OpenPrinterW", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool OpenPrinter(string src, ref IntPtr hPrinter , long pd);

    [DllImport("winspool.drv", EntryPoint="ClosePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool ClosePrinter(IntPtr hPrinter);

    [DllImport("winspool.drv", EntryPoint="StartDocPrinterW", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, ref DOCINFOW pDI);

    [DllImport("winspool.drv", EntryPoint="EndDocPrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool EndDocPrinter(IntPtr hPrinter);

    [DllImport("winspool.drv", EntryPoint="StartPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool StartPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.drv", EntryPoint="EndPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool EndPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.drv", EntryPoint="WritePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
    private static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, ref Int32 dwWritten);

    #endregion //Win32

    // SendBytesToPrinter()
    // When the function is given a printer name and an unmanaged array of
    // bytes, the function sends those bytes to the print queue.
    // Returns True on success or False on failure.
    public bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
    {
    IntPtr hPrinter; // The printer handle.
    Int32 dwError; // Last error - in case there was trouble.
    DOCINFOW di; // Describes your document (name, port, data type).
    Int32 dwWritten; // The number of bytes written by WritePrinter().
    bool bSuccess; // Your success code.

    di = new DOCINFOW();
    di.pDocName = "Report Document";
    di.pDataType = "RAW";

    bSuccess = false;
    hPrinter = new IntPtr(0);
    dwWritten = 0;

    if(OpenPrinter(szPrinterName, ref hPrinter, 0))
    {
    if(StartDocPrinter(hPrinter, 1, ref di))
    {
    if(StartPagePrinter(hPrinter))
    {
    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
    EndPagePrinter(hPrinter);
    }
    EndDocPrinter(hPrinter);
    }
    ClosePrinter(hPrinter);
    }

    if(!bSuccess)
    {
    dwError = Marshal.GetLastWin32Error();
    }

    return bSuccess;
    }

    // When the function is given a string and a printer name,
    // the function sends the string to the printer as raw bytes.
    public void SendStringToPrinter(string szPrinterName, string szString)
    {
    IntPtr pBytes;
    Int32 dwCount;

    //How many characters are in the string?
    dwCount = szString.Length;

    //Assume that the printer is expecting ANSI text, and then convert
    //the string to ANSI text.

    pBytes = Marshal.StringToCoTaskMemAnsi(szString);
    //Send the converted ANSI string to the printer.
    SendBytesToPrinter(szPrinterName, pBytes, dwCount);
    Marshal.FreeCoTaskMem(pBytes);
    }

    // SendFileToPrinter()
    // When the function is given a file name and a printer name,
    // the function reads the contents of the file and sends the
    // contents to the printer.
    // Presumes that the file contains printer-ready data.
    // Shows how to use the SendBytesToPrinter function.
    // Returns True on success or False on failure.

    public bool SendFileToPrinter(string szPrinterName, string szFileName)
    {
    // Open the file.
    FileStream fs;
    fs = new FileStream(szFileName, FileMode.Open);
    // Create a BinaryReader on the file.
    BinaryReader br;
    br = new BinaryReader(fs);
    //Dim an array of bytes large enough to hold the file's contents.
    byte[] bytes;

    bytes = new byte[fs.Length];

    bool bSuccess;
    //Your unmanaged pointer.
    IntPtr pUnmanagedBytes;
    //Read the contents of the file into the array.

    bytes = br.ReadBytes((int)fs.Length);

    // Allocate some unmanaged memory for those bytes.
    pUnmanagedBytes = Marshal.AllocCoTaskMem((int)fs.Length);
    // Copy the managed byte array into the unmanaged array.
    Marshal.Copy(bytes, 0, pUnmanagedBytes, (int)fs.Length);
    // Send the unmanaged bytes to the printer.
    bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, (int)fs.Length);
    // Free the unmanaged memory that you allocated earlier.
    Marshal.FreeCoTaskMem(pUnmanagedBytes);
    return bSuccess;
    }

    public string ConvertWindowsToOEM437Greek(string sWindows)
    {
    string sOEM437Greek="";
    if(sWindows != "")
    {
    for(int i = 0; i {
    switch(sWindowsIdea [I])
    {
    case 'Ε':
    sOEM437Greek+="i";
    break;
    case 'Ρ':
    sOEM437Greek+="i";
    break;
    case 'Τ':
    sOEM437Greek+="i";
    break;
    case 'Υ':
    sOEM437Greek+="i";
    break;
    case 'Θ':
    sOEM437Greek+="i";
    break;
    case 'Ι':
    sOEM437Greek+="i";
    break;
    case 'Ο':
    sOEM437Greek+="i";
    break;
    case 'Π':
    sOEM437Greek+="i";
    break;
    case 'Α':
    sOEM437Greek+="i";
    break;
    case 'Σ':
    sOEM437Greek+="i";
    break;
    case 'Δ':
    sOEM437Greek+="i";
    break;
    case 'Φ':
    sOEM437Greek+="i";
    break;
    case 'Γ':
    sOEM437Greek+="i";
    break;
    case 'Η':
    sOEM437Greek+="i";
    break;
    case 'Ξ':
    sOEM437Greek+="i";
    break;
    case 'Κ':
    sOEM437Greek+="i";
    break;
    case 'Λ':
    sOEM437Greek+="i";
    break;
    case 'Ζ':
    sOEM437Greek+="i";
    break;
    case 'Χ':
    sOEM437Greek+="i";
    break;
    case 'Ψ':
    sOEM437Greek+="i";
    break;
    case 'Ω':
    sOEM437Greek+="i";
    break;
    case 'Β':
    sOEM437Greek+="i";
    break;
    case 'Ν':
    sOEM437Greek+="i";
    break;
    case 'Μ':
    sOEM437Greek+="i";
    break;
    default:
    sOEM437Greek+=sWindowsIdea [I];
    break;
    }
    }
    }
    return sOEM437Greek;
    }


    }
    }
  •  17-11-2005, 22:10 7153 σε απάντηση της 7022

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    P.S. kapo sto msdn iparxei kai o andistixos kodikas gia VB
    psakse sto google gia Print Raw Data From VB.NET
  •  18-11-2005, 09:52 7162 σε απάντηση της 7153

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Και δεν τα γράφεις σε ένα αρχείο και στέλνεις το αρχείο για εκτύπωση?
  •  18-11-2005, 10:52 7164 σε απάντηση της 7162

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Ή να χρησιμοποιήσεις τον κώδικα από αυτό το post  για να κάνεις τη μετατροπή σε ελληνικά. Πάντως τον πιο σύντομο κώδικα για μετατροπές τον έχει γράψει ο isidoros:



    Imports System.Text

    Dim enc_result As System.Text.Encoding = Encoding.ASCII.GetEncoding(737)
    Dim enc_SOURCE As System.Text.Encoding = Encoding.ASCII.GetEncoding(1253)

    Private Function Encode(ByVal STR As String) As String
        Return enc_result.GetString(enc_SOURCE.GetBytes(STR))
    End Function

    Δεν μπορώ να πω ότι κατάλαβα την ConvertWindowsToOEM437Greek, μου φαίνεται ότι κάνει ότι και η κλάση Encoding.

    Και μια συμβουλή. Μην γράφετε με λατινικούς χαρακτήρες γιατί από τη μια κάνουν το μήνυμα δυσανάγνωστο από την άλλη χάνεται η δυνατότητα αναζήτησης. Τα δυσανάγνωστα μηνύματα είναι πολύ εύκολο να αγνοηθούν και να μην πάρουν ποτέ απάντηση.


    Παναγιώτης Καναβός, Freelancer
    Twitter: http://www.twitter.com/pkanavos
  •  18-11-2005, 12:01 7168 σε απάντηση της 7022

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Σωστή ι παρατήρηση για τα ελληνικά
    Για την ConvertWindowsToOEM437Greek ναι αυτό κάνει – μετατρέπει τα 737(Windows) σε 437(Greek Dos).
    Δεν ήξερα ότι υπάρχει έτοιμη στο .NET convert se παλιά (437) ελληνικά :)
    Για την παρατήρηση το φίλο μας pontifikas - ε είναι λίγο καλύτερη ι προτεινόμενη λύση όπως και να το κάνουμε.
  •  10-04-2006, 09:25 11743 σε απάντηση της 7022

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

     

    Είχα ένα τηλέφωνο από έναν άνθρωπο από το Βόλο και μου ζήτησε την μετατροπή που είχα κάνει στο MSAccess.
    Τη παραθέτω.

    '======================================================================
    'TRANSLATE FONT TO DOTMATRIX CHARSET
    '======================================================================
    Private Function StrTrans(str As String) As String
    Dim i As Integer
    Dim outStr As String, S As Byte
        For i = 1 To Len(str)
            S = Asc(Mid(str, i, 1))
            Select Case S
                Case 193: outStr = outStr & Chr(128)    '"Α"
                Case 162: outStr = outStr & Chr(128)    '"Ά"
                Case 194: outStr = outStr & Chr(129)    '"Β"
                Case 195: outStr = outStr & Chr(130)    '"Γ"
                Case 196: outStr = outStr & Chr(131)    '"Δ"
                Case 197: outStr = outStr & Chr(132)    '"Ε"
                Case 184: outStr = outStr & Chr(132)    '"Έ"
                Case 198: outStr = outStr & Chr(133)    '"Ζ"
                Case 199: outStr = outStr & Chr(134)    '"Η"
                Case 185: outStr = outStr & Chr(134)    '"Ή"
                Case 200: outStr = outStr & Chr(135)    '"Θ"
                Case 201: outStr = outStr & Chr(136)    '"Ι"
                Case 186: outStr = outStr & Chr(136)    '"Ί"
                Case 202: outStr = outStr & Chr(137)    '"Κ"
                Case 203: outStr = outStr & Chr(138)    '"Λ"
                Case 204: outStr = outStr & Chr(139)    '"Μ"
                Case 205: outStr = outStr & Chr(140)    '"Ν"
                Case 206: outStr = outStr & Chr(141)    '"Ξ"
                Case 207: outStr = outStr & Chr(142)    '"Ο"
                Case 188: outStr = outStr & Chr(142)    '"Ό"
                Case 208: outStr = outStr & Chr(143)    '"Π"
                Case 209: outStr = outStr & Chr(144)    '"Ρ"
                Case 211: outStr = outStr & Chr(145)    '"Σ"
                Case 212: outStr = outStr & Chr(146)    '"Τ"
                Case 213: outStr = outStr & Chr(147)    '"Υ"
                Case 190: outStr = outStr & Chr(147)    '"Ύ"
                Case 214: outStr = outStr & Chr(148)    '"Φ"
                Case 215: outStr = outStr & Chr(149)    '"Χ"
                Case 216: outStr = outStr & Chr(150)    '"Ψ"
                Case 217: outStr = outStr & Chr(151)    '"Ω"
                Case 191: outStr = outStr & Chr(151)    '"Ώ"
                Case 225: outStr = outStr & Chr(152)    '"α"
                Case 226: outStr = outStr & Chr(153)    '"β"
                Case 227: outStr = outStr & Chr(154)    '"γ"
                Case 228: outStr = outStr & Chr(155)    '"δ"
                Case 229: outStr = outStr & Chr(156)    '"ε"
                Case 230: outStr = outStr & Chr(157)    '"ζ"
                Case 231: outStr = outStr & Chr(158)    '"η"
                Case 232: outStr = outStr & Chr(159)    '"θ"
                Case 233: outStr = outStr & Chr(160)    '"ι"
                Case 234: outStr = outStr & Chr(161)    '"κ"
                Case 235: outStr = outStr & Chr(162)    '"λ"
                Case 236: outStr = outStr & Chr(163)    '"μ"
                Case 237: outStr = outStr & Chr(164)    '"ν"
                Case 238: outStr = outStr & Chr(165)    '"ξ"
                Case 239: outStr = outStr & Chr(166)    '"ο"
                Case 240: outStr = outStr & Chr(167)    '"π"
                Case 241: outStr = outStr & Chr(168)    '"ρ"
                Case 243: outStr = outStr & Chr(169)    '"σ"
                Case 242: outStr = outStr & Chr(170)    '"ς"
                Case 244: outStr = outStr & Chr(171)    '"τ"
                Case 245: outStr = outStr & Chr(172)    '"υ"
                Case 246: outStr = outStr & Chr(173)    '"φ"
                Case 247: outStr = outStr & Chr(174)    '"χ"
                Case 248: outStr = outStr & Chr(175)    '"ψ"
                Case 249: outStr = outStr & Chr(224)    '"ω"
                Case 220: outStr = outStr & Chr(225)    '"ά"
                Case 221: outStr = outStr & Chr(226)    '"έ"
                Case 222: outStr = outStr & Chr(227)    '"ή"
                Case 250: outStr = outStr & Chr(228)    '"ϊ"
                Case 223: outStr = outStr & Chr(229)    '"ί"
                Case 252: outStr = outStr & Chr(230)    '"ό"
                Case 253: outStr = outStr & Chr(231)    '"ύ"
                Case 251: outStr = outStr & Chr(232)    '"ϋ"
                Case 254: outStr = outStr & Chr(233)    '"ώ"
                Case 128: outStr = outStr & Chr(238)    '"€"
                Case 218: outStr = outStr & Chr(136)    '"Ϊ"
                Case 219: outStr = outStr & Chr(147)    '"Ϋ"
                Case Else: outStr = outStr & Chr(S)
            End Select
        Next i
        StrTrans = outStr
    End Function


    while (!dead) learn();
  •  22-04-2006, 00:35 12064 σε απάντηση της 7022

    Απ: Εκτύπωση απο Visual Basic .net 2005 σε εκτυπωτή Dot Matrix

    Συνημμένα: WinPrinter.zip

    Σου στέλνω σε συνημμένο το library είναι γραμμένο από τον gcapnias απλά και σίγουρα πράγματα

    Το πρόβλημα είναι στο Compatible, τα βασικά

    Commands που πρέπει να στέλνης στον εκτυπωτή υπάρχουν για περισσότερο έλεγχο μπορείς να βρής στο internet το emulation της IBM που τον υποστιρήζουν αν όχι όλοι οι περισσότεροι εκτυπωτές η πάνε στην ιστοσελίδα του κατασκευαστή για να κάνεις λήψη το manual που περιέχει και τα commands

Προβολή Τροφοδοσίας RSS με μορφή XML
Με χρήση του Community Server (Commercial Edition), από την Telligent Systems