如何設定保存印表機紙張大小
當印表機紙張設定A5格式若程式碼調用a4實際在印表機裡面的紙張設定還是A5所以可以利用下列程式碼控制
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Public Class Page
_
Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean
End Function
_ Public Shared Function ClosePrinter(ByVal phPrinter As IntPtr) As Integer
End Function
_
Public Shared Function SetPrinter(ByVal hPrinter As IntPtr, ByVal level As Integer, ByVal lpBytes As IntPtr, ByVal command As Integer) As Boolean
End Function
Public Shared Function Setting(ByVal PageName As String) As Boolean
Try
Dim printerSettings As PrinterSettings
Dim document As New PrintDocument()
printerSettings = document.PrinterSettings
Dim hPrinter As IntPtr
OpenPrinter(printerSettings.PrinterName, hPrinter, 0)
Dim p As PaperSize = Nothing
Dim ps As PaperSize
For Each ps In document.PrinterSettings.PaperSizes
If ps.PaperName.Equals(PageName) Then
p = ps
End If
Next
document.DefaultPageSettings.PaperSize = p
Dim hDevMode As IntPtr = printerSettings.GetHdevmode(document.DefaultPageSettings)
Dim ret As Boolean = SetPrinter(hPrinter, 9, hDevMode, 0)
ClosePrinter(hPrinter)
Return True
Catch ex As Exception
End Try
End Function
End Class
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Public Class Page
Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As Long) As Boolean
End Function
End Function
End Function
Public Shared Function Setting(ByVal PageName As String) As Boolean
Try
Dim printerSettings As PrinterSettings
Dim document As New PrintDocument()
printerSettings = document.PrinterSettings
Dim hPrinter As IntPtr
OpenPrinter(printerSettings.PrinterName, hPrinter, 0)
Dim p As PaperSize = Nothing
Dim ps As PaperSize
For Each ps In document.PrinterSettings.PaperSizes
If ps.PaperName.Equals(PageName) Then
p = ps
End If
Next
document.DefaultPageSettings.PaperSize = p
Dim hDevMode As IntPtr = printerSettings.GetHdevmode(document.DefaultPageSettings)
Dim ret As Boolean = SetPrinter(hPrinter, 9, hDevMode, 0)
ClosePrinter(hPrinter)
Return True
Catch ex As Exception
End Try
End Function
End Class
留言