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.

Keywords:

Written by admin on January 21st, 2010 with no comments.
Read more articles on Knowledge Base and Programming.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .