Programming: Crystal report custom papersize printout

Was facing some problem in printing the custom paper sized crystal report which is meant for label. During development, the report shown correctly and perfectly nice. However, upon implementing to client’s server, the report is loaded onto a different sized paper (other than the customized one). A little research here and there with trial and testing, manage to get the crystal report working. An additional codes is required and below is the functional code:

Private Sub reportPrinterSEtup()
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = “Microsoft XPS Document Writer” ‘(ex. “Epson SQ-1170 ESC/P 2”)
For i = 0 To doctoprint.PrinterSettings.PaperSizes.Count – 1
Dim rawKind As Integer
If UCase(doctoprint.PrinterSettings.PaperSizes(i).PaperName) = ucase(“LABEL”) Then
rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField(“kind”, Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
crReportDocument.PrintOptions.PaperSize = rawKind
Exit For
End If
Next
End Sub

The doctoprint.PrinterSettings.PrinterName requires a valid printer name which exist in the hosting site. I’ve used “Microsoft XPS Document Writer” as it seems to be bundled together with Windows. The “LABEL” value will have to change to the name of custom papersize created. Note that the values are case sensitive.

Leave a Reply

Your email address will not be published. Required fields are marked *