0
Answer

Setting Custom Paper Size at runtime and before printing

Minesh

Minesh

12y
3.3k
1
Hi,

I am using VB.Net 2010 and Crystal Reports.

I want to print on a custom paper size but everytime my report is generated, and I click on the Print button, under the Printer Preference the paper size is always Letter. In the code below I am try to change it and the code is executed without any error but still under printer perference the Paper size is Letter.

Can anyone help me out?

cmd.CommandText = ("SELECT * FROM StockItem")
cmd.Connection = Con
con.Open()
DSRpt.Clear()
DA.SelectCommand = (cmd)
DA.Fill(DSRpt, cmd.CommandText)
DTRpt = DSRpt.Tables(0)

rptDoc = New ReportDocument
Dim rptPath As String = Application.StartupPath & "\CrystalReceipt.rpt"
rptDoc.Load(rptPath)
rptDoc.SetDataSource(DTRpt)
frmRptViewer.Text = "Print Sales Order"
Con.Close()
frmRptViewer.CrystalReportViewer1.ReportSource = rptDoc
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = "EPSON LQ-300+ /II ESC/P 2" '"EPSON LQ-300+II ESC/P2" '(ex. "Epson SQ-1170 ESC/P 2")
For i = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
   Dim rawKind As Integer
   If doctoprint.PrinterSettings.PaperSizes(i).PaperName = "A6 LR" Then
      rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
      rptDoc.PrintOptions.PaperSize = rawKind
      Exit For
   End If
Next
frmRptViewer.ShowDialog()
frmRptViewer.Dispose()
rptDoc = Nothing

Thank you and your help will highly be appreciated