Warning: Illegal string offset 'before_widget' in /home/mhd-01/www.krosa.it/htdocs/blog/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 769
Warning: Illegal string offset 'after_widget' in /home/mhd-01/www.krosa.it/htdocs/blog/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 771
Warning: Illegal string offset 'before_title' in /home/mhd-01/www.krosa.it/htdocs/blog/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 773
Warning: Illegal string offset 'after_title' in /home/mhd-01/www.krosa.it/htdocs/blog/wp-content/plugins/mycustomwidget/my_custom_widget_functions.php on line 775
Note: English Reader click here
Vedro’ di farla semplice…
Per necessità lavorative mi sono imbattutto nella necessità di dover creare dei report con Crystal Report for .NET (quello incluso in VS.NET 2002) con un formato di carta custom (un modulozzo continuo pre-perforato, non standard, cazzi e mazzi ecc.ecc.)
Problema: la stampa del report funziona bene solo sul pc di sviluppo, quando si fa il deploy il formato va letteralmente a farsi fottere.
Cerco un po’ in giro ma niente, trovo solo tanta altra gente con il mio stesso problema e nessuna soluzione seria (solo qualche richiamo a dei riti voodoo o al Santo Graal…ora non ricordo bene…)
In preda allo sconforto mi imbatto più o meno casualmente in un documento della Crystal Decision (‘tacci loro!) che elucubra sul modo in cui Crystal Report interagisce con i driver della stampante…questa “affascinante” lettura mi mette la pulce nell’orecchio…la soluzione la trovate qui sotto (è in inglese perchè caso mai qualche altro disperato arrivi qui da qualche googlata riesce a capirci qualcosa )
I can’t believe CR is acting in such a (stupid) way!
The fact is that crystal report save the information of the format of a report in a non-portable way!
It saves the “ID” of the format instead of his “Name”!
The problem is that in Windows this ID is machine dependent.
The trick is very simple:
1 – Search on the system for the printer you want to use.
2 – Cycle over all the supported format searching for your custom format (I search it by name but you can search it also by dimensions (in inches)).
3 – Get the ID.
4 – Assign it to the report’s PaperSize property.
5 – Bingo!
Here it is a quick example (in VB.NET):
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
Read the original thread on MSDN forum here