2

我已经创建了自定义纸张尺寸“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 尺寸,否则会在尺寸预览中显示自定义纸张?有没有更好的方法来实现我的目标?

4

2 回答 2

3

此方法适用于Epson LX-300+ ii Dot-Matrix Printer及更高型号

如果您使用的是打印机,特别是用于打印收据 ,这里是有关如何将打印机设置为所需纸张尺寸的步骤

首先设置要使用的打印机:转到打印机中的设备和打印机 ,选择您要使用的打印机并单击 - 右键单击​​打印机属性 单击首选项...按钮。在选项卡 -将文档大小更改为用户定义 下,将出现一个新的新窗口。在纸张大小名称中指定名称(即 OR 纸张)并根据需要更改纸张宽度和高度单击保存然后确定

在此处输入图像描述 然后通过按右键单击设置您的打印机,然后设置为默认打印机

为您的打印添加这些代码行。您仍然可以使用参数和数据集。

Dim c As Integer
    Dim doctoprint As New System.Drawing.Printing.PrintDocument()
    doctoprint.PrinterSettings.PrinterName = "EPSON L1300 Series"
    Dim rawKind As Integer
    For c = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
        If doctoprint.PrinterSettings.PaperSizes(c).PaperName = "OR Receipts" Then
            rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(c).GetType().GetField("kind", Reflection.BindingFlags.Instance Or 

Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(c)))
            Exit For
        End If
    Next

    Report1.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
    frmPreview.CrystalReportViewer1.ReportSource = Report1
    Report1.PrintToPrinter(1, False, 1, 1)
于 2016-03-10T06:25:02.920 回答
2

你可以这样做

var rep = new YursCrystalReport();
var printerSettings = new System.Drawing.Printing.PrinterSettings();
var pSettings = new System.Drawing.Printing.PageSettings(printerSettings); 
pSettings.PaperSize = new System.Drawing.Printing.PaperSize("newsize", 3000, 3000);//custom size  hundredths (100=1 inch)
pSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
rep.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
rep.PrintOptions.CopyFrom(printerSettings, pSettings);
于 2019-03-28T10:15:45.423 回答