2013-07-24 73 views
1

我已創建自定義紙張尺寸自定義紙張尺寸「人聯黨15×14」在Setting - Printers - File - Server Properties.現在我想要使用VB.net 2005編程設置水晶報表

當設置自定義紙張尺寸的水晶報表我從VB.net運行報表,Crystal報表查看器顯示自定義紙張尺寸的正確預覽,但是當我給出打印命令時,它將使用默認打印機紙張尺寸進行打印。 (如Letter)

下面是我用打印的代碼:

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類中。

上述代碼有什麼問題?爲什麼打印Letter Size時Crystal Report預覽會在大小預覽中顯示自定義紙張?有沒有更好的方法來實現我的目標?

+0

沒有人有任何答案?我在工作中遇到了完全相同的問題。 –

+0

默認情況下,可能是Printer設置爲_「Letter Size」_。現在還沒有答案,現在是2016年 –

回答

0

此方法適用於一個愛普生LX-300 + II點陣打印機後來的型號

如果您使用的是打印機尤其是對打印收據 下面是關於如何設置的步驟你使用打印機所需的紙張尺寸

首先設置打印機: 轉到設備和打印機 在打印機選擇您要使用並單擊打印機 - 右鍵打印機屬性 單擊首選項...按鈕。 Main Tab - 更改文檔大小用戶定義 將出現一個新的新窗口。 在紙張尺寸名稱指定的名稱(即或紙) 和改變紙張的寬度和高度根據需要 點擊保存然後OK

enter image description here 然後按右鍵然後設置爲默認設置打印機打印機

爲您的打印添加這些代碼行。您仍然可以使用參數和數據集。

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)