Microsoft Developer Network > 포럼 홈 > Visual Basic Interop and Upgrade > HP PCL Banner creation and printing on a server
질문하기질문하기
 

답변됨HP PCL Banner creation and printing on a server

  • 2008년 1월 3일 목요일 오후 8:37Tim_Shaf 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

     

    The following code is used to create a banner page that is pre-pended to a PCL print-stream
    and then binary copied to a network printer. The concept is that since the PCL creation is
    performed on a server, the banner page needs to be created and printed immediately before
    the document so that the requestor is identified with the banner page.

     

    I am just getting my feet wet with .Net and in the process of moving some of my VB6
    code into .Net.

     

    1. CreateBannerPS - This routine works fine, but it uses the Scripting.FileSystemObject. I am
        trying to replace this functionality without using the Scripting.FileSystemObject. This is the
        method I used in VB6.
    2. CreateBannerPSNew is my attempt to replace this functionality. It works except an additional
        page containing some symbols is printed prior to the banner page.

     

    Questions
    1. What needs to be done to prevent the page with the symbols?
    2. Is there a better method for embedding the escape characters?

     

    Appreciate all comments
    Tim


    Option Strict On
    Option Explicit On

     

    Module Banner

      Sub Main()
        Dim OUTPUT_DIR As String = My.Application.Info.DirectoryPath
        Dim FName As String = "Test.pcl"
        Dim sUser As String = "TBS2"
        Dim sPrinter As String = "HP78"
        'Debug.Print("Old Method: " & Banner.CreateBannerPS(Path:=OUTPUT_DIR, _
        '  FName:="Old.pcl", UserId:=sUser, sPrinter:=sPrinter))
        'Debug.Print("New Method: " & Banner.CreateBannerPSNew(Path:=OUTPUT_DIR, _
        '  FName:="New.pcl", UserId:=sUser, sPrinter:=sPrinter))
        'Exit Sub
        If Banner.CreateBannerPSNew(Path:=OUTPUT_DIR, FName:=FName, _
            UserId:=sUser, sPrinter:=sPrinter) Then
          Debug.Print("Ok")
          BinaryPrint(FName:=OUTPUT_DIR & "\" & FName, _
            sPrinter:="z_" & sPrinter & "$")
        Else
          Debug.Print("Error")
        End If
        If Banner.CreateBannerPS(Path:=OUTPUT_DIR, FName:=FName, _
            UserId:=sUser, sPrinter:=sPrinter) Then
          Debug.Print("Ok")
          BinaryPrint(FName:=OUTPUT_DIR & "\" & FName, _
            sPrinter:="z_" & sPrinter & "$")
        Else
          Debug.Print("Error")
        End If
      End Sub

     

      'Creates Banner Sheet Print-Stream file
      Function CreateBannerPSNew(ByVal Path As String, ByVal FName As String, _
        ByVal UserId As String, ByVal sPrinter As String) As Boolean
        Dim Txt As String = ""
        CreateBannerPSNew = False
        Txt = "%-12345X@PJL ENTER LANGUAGE=PCL" & vbCrLf 'Enter PCL language
        Txt += "E" & vbCrLf 'Printer Reset
        Txt += "*t600R" & vbCrLf 'Resolution - 600 DPI
        Txt += "&u600D" & vbCrLf 'Unit-of-Measure - units per inch
        Txt += "*r0F" & vbCrLf 'Presentation
        Txt += "&l0o1E" & vbCrLf 'Top Margin
        Txt += "&l0S" & vbCrLf 'Simplex/Duplex
        Txt += "&l7H" & vbCrLf 'Paper Source
        Txt += "&l2a8c1E" & vbCrLf 'Top Margin
        Txt += "*p0x0Y" & vbCrLf 'Units of Measure
        Txt += "*c0t5760x7704Y" & vbCrLf '???
        Txt += "&l1X" & vbCrLf 'Number of copies
        Txt += "*b0M" & vbCrLf 'Compression mode
        'Font Id, Typeface, Stroke weight, style, pitch, spacing
        Txt += "(19U(s4099t0b0s10h0P" & vbCrLf
        Txt += "&d@" & vbCrLf 'Underline disable
        Txt += "*v0o0T" & vbCrLf 'transparency mode, current pattern
        Txt += "*p415Y  *p330X===================================" & _
          "=========================" & vbCrLf
        Txt += "(19U" 'Symbol set - Windows ANSI
        Txt += "(s4099T" 'Typeface - Courier (Scalable)
        Txt += "(s-4B" 'Stroke Weight: -4 Extra Light - Does not seem to work
        Txt += "(s0S" 'Style: 0-Upright, 1-Italic, 32-Outline - Does not seem to work
        Txt += "(s0.75H" 'Pitch - characters per inch
        Txt += "(s0P" 'Spacing - 0 for fixed, 1 for proportional
        Txt += "*p1600Y  *p600X" & UserId & vbCrLf
        Txt += "(19U(s4099t0b0s10h0P&d@" & vbCrLf
        Txt += "*p2200Y  *p330XPrint Server:*p1225X" & _
          Replace(Replace(Replace(sPrinter, "z_", ""), "$", ""), "\\", "") & vbCrLf
        Txt += "*p2300Y  *p330XDate Printed:*p1225X" & _
          Format(Now, "MM/dd/yyyy") & vbCrLf
        Txt += "*p2400Y  *p330XTime Printed:*p1225X" & _
          Format(Now, "hh:mms tt") & vbCrLf
        Txt += "*p2600Y *p330X===================================" & _
          "=========================" & vbCrLf

        '    Txt += "E" & vbCrLf 'Printer Reset

        My.Computer.FileSystem.WriteAllText(Path & "\" & FName, Txt, False, _
          System.Text.Encoding.UTF8)
        If Err.Number = 0 Then CreateBannerPSNew = True
      End Function

     

      'Creates Banner Sheet Print-Stream file
      Function CreateBannerPS(ByVal Path As String, ByVal FName As String, _
        ByVal UserId As String, ByVal sPrinter As String) As Boolean
        Dim fso As New Scripting.FileSystemObject
        Dim ts As Scripting.TextStream
        CreateBannerPS = False
        ts = fso.CreateTextFile(Path & "\" & FName, True) 'Overwrites existing file
        ts.WriteLine("%-12345X@PJL ENTER LANGUAGE=PCL") 'Enter PCL language
        ts.WriteLine("E") 'Printer Reset
        ts.WriteLine("*t600R") 'Resolution - 600 DPI
        ts.WriteLine("&u600D") 'Unit-of-Measure - units per inch
        ts.WriteLine("*r0F") 'Presentation
        ts.WriteLine("&l0o1E") 'Top Margin
        ts.WriteLine("&l0S") 'Simplex/Duplex
        ts.WriteLine("&l7H") 'Paper Source
        ts.WriteLine("&l2a8c1E") 'Top Margin
        ts.WriteLine("*p0x0Y") 'Units of Measure
        ts.WriteLine("*c0t5760x7704Y") '???
        ts.WriteLine("&l1X") 'Number of copies
        ts.WriteLine("*b0M") 'Compression mode
        'Font Id, Typeface, Stroke weight, style, pitch, spacing
        ts.WriteLine("(19U(s4099t0b0s10h0P")
        ts.WriteLine("&d@") 'Underline disable
        ts.WriteLine("*v0o0T") 'transparency mode, current pattern
        ts.WriteLine("*p415Y  *p330X===================================" & _
          "=========================")
        ts.Write("(19U") 'Symbol set - Windows ANSI
        ts.Write("(s4099T") 'Typeface - Courier (Scalable)
        ts.Write("(s-4B") 'Stroke Weight: -4 Extra Light - Does not seem to work
        ts.Write("(s0S") 'Style: 0-Upright, 1-Italic, 32-Outline - Does not seem to work
        ts.Write("(s0.75H") 'Pitch - characters per inch
        ts.Write("(s0P") 'Spacing - 0 for fixed, 1 for proportional
        ts.WriteLine("*p1600Y  *p600X" & UserId)
        ts.WriteLine("(19U(s4099t0b0s10h0P&d@")
        ts.WriteLine("*p2200Y  *p330XPrint Server:*p1225X" & _
          Replace(Replace(Replace(sPrinter, "z_", ""), "$", ""), "\\", ""))
        ts.WriteLine("*p2300Y  *p330XDate Printed:*p1225X" & _
          Format(Now, "MM/dd/yyyy"))
        ts.WriteLine("*p2400Y  *p330XTime Printed:*p1225X" & _
          Format(Now, "hh:mms tt"))
        ts.WriteLine("*p2600Y *p330X===================================" & _
          "=========================")
        ts.Close()
        ts = Nothing
        fso = Nothing
        If Err.Number = 0 Then CreateBannerPS = True
      End Function

     

      Sub BinaryPrint(ByVal FName As String, ByVal sPrinter As String)
        Dim p As Process = New Process
        Dim i As Integer = 0
        Dim sArg As String = "/C Copy /b """ & FName & """ \\Dcpp100\" & sPrinter
        Debug.Print(sArg)
        With p.StartInfo
          .FileName = "cmd.exe"
          .Arguments = sArg
          .UseShellExecute = False
          .CreateNoWindow = True
        End With
        p.Start()
        While Not p.HasExited
          Debug.Print("BinaryPrint CloseWindow " & CStr(i))
          i += 1
          System.Threading.Thread.Sleep(1000)     'Sleep for 1 second
          If i >= 10 Then
            Debug.Print("BinaryPrint kill process required")
            p.Kill()
            Exit While
          End If
        End While
        p.Dispose()
      End Sub

     

    End Module

답변

  • 2008년 2월 12일 화요일 오후 4:10Tim_Shaf 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    I discovered that if I use "System.IO.File.WriteAllText" to replace "My.Computer.FileSystem.WriteAllText" the

    additional page and symbols are not printed.

모든 응답

  • 2008년 2월 12일 화요일 오후 4:10Tim_Shaf 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    I discovered that if I use "System.IO.File.WriteAllText" to replace "My.Computer.FileSystem.WriteAllText" the

    additional page and symbols are not printed.