我已经创建了自定义纸张尺寸“SUPP 15 x 14”,Setting - Printers - File - Server Properties.
现在我正在尝试使用 VB.net 2005 为 Crystal Report 设置自定义纸张尺寸。
当我从 VB.net 运行报表时,Crystal 报表查看器会显示自定义纸张大小的正确预览,但是当我发出打印命令时,它会使用默认的打印机纸张大小进行打印。(例如信)
这是我用来打印的代码:
Public Sub ...
'...
Dim ObjCrReport as new ReportDocument
'...
ObjCrReport.SetDataSource(ObjPrintDataSet.Tables("PrintData"))
SetReportPageSize("SUPP 15 x 14", 1)
'...
End Sub
Private Sub BtnPrintDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrintDoc.Click
Try
'Print command
ObjCrReport.PrintToPrinter(1, False, 0, 0)
Catch ex As Exception
MessageBox.Show(ex.Message, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub SetReportPageSize(ByVal mPaperSize As String, ByVal PaperOrientation As Integer)
Try
Dim ObjPrinterSetting As New System.Drawing.Printing.PrinterSettings
Dim PkSize As New System.Drawing.Printing.PaperSize
ObjPrinterSetting.PrinterName = "Epson FX1170"
For i As Integer = 0 To ObjPrinterSetting.PaperSizes.Count - 1
If ObjPrinterSetting.PaperSizes.Item(i).PaperName = mPaperSize.Trim Then
PkSize = ObjPrinterSetting.PaperSizes.Item(i)
Exit For
End If
Next
If PkSize IsNot Nothing Then
Dim myAppPrintOptions As CrystalDecisions.CrystalReports.Engine.PrintOptions = ObjCrReport.PrintOptions
myAppPrintOptions.PrinterName = "Epson FX1170"
myAppPrintOptions.PaperSize = CType(PkSize.RawKind, CrystalDecisions.Shared.PaperSize)
ObjCrReport.PrintOptions.PaperOrientation = IIf(PaperOrientation = 1, _
CrystalDecisions.Shared.PaperOrientation.Portrait, _
CrystalDecisions.Shared.PaperOrientation.Landscape)
End If
PkSize = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
如果我使用myAppPrintOptions.PaperSize = PaperSize.PaperLegal
,则打印预览和打印显示正确,但我想设置未在PaperSize
课堂上显示的自定义纸张尺寸。
上面的代码有什么问题?为什么在 Crystal 报表预览中打印 Letter 尺寸,否则会在尺寸预览中显示自定义纸张?有没有更好的方法来实现我的目标?