Symptom
- ReportDocument.PrintOptions.PaperSize = PaperSize.PaperEnvelopeC6 does guarantee the correct size will be set
Cause
- Crystal Reports saves the paper size Enum internally
- An Enum paper size is machine dependent and thus may not be correct on different computers and printers
Resolution
- There are two solutions
1) Determine the correct Enum on each computer and then set the paper size to it:
Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
crReportDocument.Load("C:\Crystal\myReport.rpt")
crReportDocument.PaperSize = <the ENUM>
- To determine the correct ENUM, use code as described in Microsoft KBase article Q282474
- A sample application using the code is atttached to this KBase
2) Using the code bellow, find the ENUM by searching for the Name of the custom paper size:
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = "YourPrinterName" '(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 = "MyCustomFormatName" Then
rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField("kind", Reflection.BindingFlags.Instance Or
Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
oRpt.PrintOptions.PaperSize = rawKind
Exit For
End If
Next
' Assign the ENUM to the report's PaperSize property (see solution (1) above)
Keywords
KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To
Product
Crystal Reports 2008 V1
Attachments
DEVCAP.zip |