or
<ctl:ReportViewer x:Name="ReportViewer1"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
ReportServerUri="../ReportService.svc"
HorizontalContentAlignment="Center"
HorizontalAlignment="Center"
VerticalContentAlignment="Top"
ViewMode="PrintPreview"
Style="{StaticResource ReportViewerStyle1}" />
- i have 3 radio button (each radio button defined a report)
- 1 button, when i click on this button, i take the name of the report : ReportViewer1.Report = "name of Report"
I am using the ReportViewer in Silverlight 5 ( version : Telerik_Reporting_Q1_2012_v6_0_12_215) and I use a ReportService.svc file to generate the report.
Thank you for your help.
public
void
RenderPdfReport(IReportDocument report,
string
documentPath)
{
ReportProcessor reportProcessor =
new
ReportProcessor();
Hashtable deviceInfo =
new
Hashtable();
deviceInfo[
"FontEmbedding"
] =
"None"
;
RenderingResult result = reportProcessor.RenderReport(
"PDF"
, report, deviceInfo);
if
(result.DocumentBytes ==
null
)
return
;
using
(FileStream fs =
new
FileStream(documentPath, FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
}
using
System;
using
System.Drawing;
using
System.Linq;
using
Telerik.Reporting.Processing;
namespace
ReportSample
{
public
class
ReportFont
{
public
static
void
AutoSizeText(DetailSection dtl,
int
minFontSize,
int
maxFontSize)
{
foreach
(Telerik.Reporting.Processing.ProcessingElement item
in
dtl.ChildElements)
{
if
(!(item
is
ReportItem))
break
;
ReportItem rptItem = (ReportItem)item;
if
(TextSizingSupported(rptItem))
{
AutoSizeText(rptItem, minFontSize, maxFontSize);
}
}
}
public
static
void
AutoSizeText(ReportItem item,
int
minFontSize,
int
maxFontSize)
{
AutoSizeText(item, minFontSize, maxFontSize,
false
);
}
public
static
void
AutoSizeText(ReportItem item,
int
minFontSize,
int
maxFontSize,
bool
forceResize)
{
if
(!forceResize && !item.Name.EndsWith(
"_rf"
))
return
;
item.Style.Font.Size = GetFontSize(item, minFontSize, maxFontSize);
}
protected
static
Font GetFont(Telerik.Reporting.Drawing.Font font)
{
return
GetFont(font.Name, font.Size.Value, font.Style);
}
protected
static
Font GetFont(Telerik.Reporting.Drawing.Font font,
float
fontSize)
{
return
GetFont(font.Name, fontSize, font.Style);
}
protected
static
Font GetFont(
string
fontName,
float
fontSize, FontStyle style)
{
FontFamily fontFamily =
new
FontFamily(fontName);
return
GetFont(fontFamily, fontSize, style);
}
protected
static
Font GetFont(FontFamily fontFamily,
float
fontSize, FontStyle style)
{
return
new
Font(fontFamily, fontSize, style);
}
protected
static
bool
TextSizingSupported(ReportItem item)
{
if
(item
is
HtmlTextBox || item
is
TextBox)
return
true
;
return
false
;
}
protected
static
Telerik.Reporting.Drawing.Unit GetFontSize(ReportItem item,
int
minFontSize,
int
maxFontSize)
{
Size textSize;
Font newFont = GetFont(item.Style.Font, maxFontSize);
Size bounds = GetBounds(item);
string
value = GetValue(item);
do
{
textSize = System.Windows.Forms.TextRenderer.MeasureText(value, newFont, bounds, System.Windows.Forms.TextFormatFlags.WordBreak);
if
(textSize.Height > bounds.Height && newFont.Size != minFontSize)
newFont = GetFont(item.Style.Font, newFont.Size - 1);
}
while
(textSize.Height > bounds.Height && newFont.Size > minFontSize);
return
Telerik.Reporting.Drawing.Unit.Point(newFont.Size);
}
protected
static
Size GetBounds(ReportItem tb)
{
Size bounds = (Size)tb.Bounds.Size;
// Adjust the bounds slightly
bounds.Height -= 3;
return
bounds;
}
protected
static
string
GetValue(ReportItem item)
{
if
(item
is
HtmlTextBox)
return
((HtmlTextBox)item).Value.ToString();
if
(item
is
TextBox)
return
((TextBox)item).Value.ToString();
throw
new
Exception(
"Unsupported ReportItem passed."
);
}
}
}