Impression sur matricielle

Résolu
joujma5 Messages postés 152 Date d'inscription samedi 11 novembre 2006 Statut Membre Dernière intervention 5 décembre 2014 - 15 avril 2013 à 10:55
joujma5 Messages postés 152 Date d'inscription samedi 11 novembre 2006 Statut Membre Dernière intervention 5 décembre 2014 - 25 mai 2013 à 13:38
Bonjour,
J'ai cherché longtemps sur un code VB.NET qui me permet de gérer l'impression sur une imprimante matricielle mais bredouille.
J'ai trouvé ailleurs un projet qui gère ça mais il est écrit en C#. y 'a t 'il quelqu'un qui pourra m'aider à le traduire en VB.NET.
Merci

4 réponses

joujma5 Messages postés 152 Date d'inscription samedi 11 novembre 2006 Statut Membre Dernière intervention 5 décembre 2014
25 mai 2013 à 13:38
Bonjour,
Voici la solution pour ceux qui ont a besoin.
1- Créer une classe nommée "LPrinter" contenant ce code:

Imports System
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Namespace LPrinterTest
Class LPrinter
<StructLayout(LayoutKind.Sequential, CharSet := CharSet.Ansi)> _
Public Class DOCINFOA
<MarshalAs(UnmanagedType.LPStr)> _
Public pDocName As String
<MarshalAs(UnmanagedType.LPStr)> _
Public pOutputFile As String
<MarshalAs(UnmanagedType.LPStr)> _
Public pDataType As String
End Class
<DllImport("winspool.Drv", EntryPoint := "OpenPrinterA", SetLastError := True, CharSet := CharSet.Ansi, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(<MarshalAs(UnmanagedType.LPStr)> szPrinter As String, ByRef hPrinter As IntPtr, pd As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "ClosePrinter", SetLastError := True, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "StartDocPrinterA", SetLastError := True, CharSet := CharSet.Ansi, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(hPrinter As IntPtr, level As Int32, <[In], MarshalAs(UnmanagedType.LPStruct)> di As DOCINFOA) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "EndDocPrinter", SetLastError := True, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "StartPagePrinter", SetLastError := True, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "EndPagePrinter", SetLastError := True, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint := "WritePrinter", SetLastError := True, ExactSpelling := True, CallingConvention := CallingConvention.StdCall)> _
Public Shared Function WritePrinter(hPrinter As IntPtr, pBytes As IntPtr, dwCount As Int32, ByRef dwWritten As Int32) As Boolean
End Function
Private HandlePrinter As IntPtr
Private ps As PrinterSettings
Public Sub New()
HandlePrinter = IntPtr.Zero
ps = New PrinterSettings()
End Sub
Public Property PrinterName() As String
Get
Return ps.PrinterName
End Get
Set
ps.PrinterName = value
End Set
End Property
Public Function ChoosePrinter() As Boolean
Dim pd As New PrintDialog()
pd.PrinterSettings = ps
If pd.ShowDialog() = DialogResult.OK Then
                ps = pd.PrinterSettings
                Return True
Else
Return False
End If
End Function
Public Function Open(DocName As String) As Boolean
If HandlePrinter <> IntPtr.Zero Then
Return False
End If
Dim risp As Boolean = OpenPrinter(ps.PrinterName, HandlePrinter, IntPtr.Zero)
If risp = False Then
Return False
End If
Dim MyDocInfo As New DOCINFOA()
MyDocInfo.pDocName = DocName
MyDocInfo.pOutputFile = Nothing
MyDocInfo.pDataType = "RAW"
If StartDocPrinter(HandlePrinter, 1, MyDocInfo) Then
StartPagePrinter(HandlePrinter)
Return True
Else
Return False
End If
End Function
Public Function Close() As Boolean
If HandlePrinter = IntPtr.Zero Then
Return False
End If
If Not EndPagePrinter(HandlePrinter) Then
Return False
End If
If Not EndDocPrinter(HandlePrinter) Then
Return False
End If
If Not ClosePrinter(HandlePrinter) Then
Return False
End If
HandlePrinter = IntPtr.Zero
Return True
End Function
Public Function Print(outputstring As String) As Boolean
If HandlePrinter = IntPtr.Zero Then
Return False
End If
Dim buf As IntPtr = Marshal.StringToCoTaskMemAnsi(outputstring)
Dim done As Int32 = 0
Dim ok As Boolean = WritePrinter(HandlePrinter, buf, outputstring.Length, done)
Marshal.FreeCoTaskMem(buf)
If Not ok Then
Return False
Else
Return True
End If
End Function
End Class
End Namespace

2- faire appel à la fonction print pour imprimer.
C'est assez simple
3
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
15 avril 2013 à 11:05
Bonjour,
Tu nous parles d'imprimante "matricielle" (qui ne se réfère qu'au mécanisme d'impression) !
Aucun mot, par contre, en ce qui concerne le fait qu'elle est en série ou en parallèle (seule chose utile à connaître pour te répondre valablement) !
Et si elle est ou non gérée par un pilote compatible Windows (notamment si en parallèle) .
Que veux-tu qu'on te réponde sur ces imprécisions-là ?
________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviendrai que si nécessité de la compléter.
0
joujma5 Messages postés 152 Date d'inscription samedi 11 novembre 2006 Statut Membre Dernière intervention 5 décembre 2014
15 avril 2013 à 11:19
bonjour,
vous avez raison, je vous présente mon problème:
j'ai essayer d'imprimer des factures sur une imprimante matricielle alors j'ai eu des grands problèmes surtout lors des saut d'une feuille à une autre, en notant que j'ai travailler avec crystal report ce qui gène aussi concernant la lenteur.
En cherchant on m'a dis d'essayer "winspool.drv". Mais sincèrement j'ai pas connu d'où commencer, et c'est ainsi que j'ai trouvé le projet en C#.
Merci
0
Utilisateur anonyme
16 avril 2013 à 00:10
Bonjour,

Tu as besoin d'un pilote d'imprimante compatible avec l'imprimante que tu veux utiliser. L'idéal étant, bien sûr, un pilote spécifique pour ton imprimante.

Il y a cet exemple chez Microsoft (Ils disent que c'est pour VB 2012. Tu peux télécharger les trois versions (Windows 8 (uniquement pour Windows 8), Desktop et Web) sur le site de Microsoft.

Ou celui-ci(Ils disent que c'est pour VB2010)

Celui-ci pour VS2008. (Il semble être l'équivalent du précédent)

Un autre

Un autre


Pour chercher un exemple dans à peu près tout que ce que Microsoft peut offrir comme exemples : All-In-One Code Framework
0
Rejoignez-nous