2

How can I change settings in my printer (driver), before printing out a PDF?

To be more specific - I want to force my printer driver to use a printer settings instead of driver defaults - basically an equivalent of clicking Properties in a Print window (which opens printer-specific settings), then Advanced Setup and ticking "Use printer settings" checkbox which is by default unticked.

But it could be anything, for example changing dithering mode in a printer.

Here is the functioning code I'm using right now for printing a PDF using my network printer:

Dim PrinterName As String = "\\MyNetwork\ZDesigner ZM400 200 dpi (ZPL)"
Dim WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter(PrinterName)

Dim PrintingPageSettings As New Printing.PageSettings()
Me.Text = PrintingPageSettings.PrinterSettings.PrinterName()

Dim isInstalled As Boolean = False
For Each InstalledPrinter As String In Printing.PrinterSettings.InstalledPrinters()
    If (PrintingPageSettings.PrinterSettings.PrinterName() = InstalledPrinter.ToString) Then
        isInstalled = True
    End If
Next
If (isInstalled) Then
    AdobeAcrobatCOM.src = Path
    AdobeAcrobatCOM.printAll()
Else
    Me.Text = PrinterName & " not found"
End If

AdobeAcrobatCOM is AxAcroPDFLib.AxAcroPDF (Adobe PDF Reader from Toolbox, COM components)

MarcinWolny
  • 1,600
  • 2
  • 27
  • 40

1 Answers1

0

Eventually I used TCP connection to the printer and printed it out this way. Here is a code sample:

    Dim PrintString As String
    Dim ipAddress As String
    Dim port As Integer

    '123123 is sample integer, "TESTstring" is sample string, Space(2) is sample of adding (two) spaces
    PrintString = String.Concat("^XA", "^FO060,080", "^BXN,5,200", "^FD", "TESTstring", 123123, "%^FS", "^FO160,100", "^ACourier,14,14", "^FD", Space(2), "^FS", "^XZ")
    ipAddress = "ZDesigner ZM400 200 dpi (ZPL)" 'yes, this works too
    port = 9100

    'Open Connection
    Dim client As New System.Net.Sockets.TcpClient
    client.Connect(ipAddress, port)

    'Write ZPL String to Connection
    Dim writer As New System.IO.StreamWriter(client.GetStream())
    writer.Write(PrintString)
    writer.Flush()

    'Close Connection
    writer.Close()
    client.Close()

You might want to look for your printer documentation. Here is a C# example for Zebra.

MarcinWolny
  • 1,600
  • 2
  • 27
  • 40