StiText Component doesn't work correctly
StiText Component doesn't work correctly
Hi there!
I'm trying to create a header and footer throungh runtime with an existing compiled report
but StiText components doesn't show any text after report is printed, my code is rigth below:
private StiReport DesenhaCabecalhoRodape(StiReport report)
{
if (identity == null) return report;
var empresa = _repositoryEmpresa.FindBy<Empresa, Int64>(identity.CompanyId);
var page = report.Pages[0];
/* Creating report page Image*/
var ms = new MemoryStream(empresa.LogoRelatorio);
var image = Image.FromStream(ms);
/* Creating report page Brush*/
var myBrush = new StiSolidBrush(Color.LightGray);
var myBrushTransparent = new StiSolidBrush(Color.Transparent);
var myBrushWhite = new StiSolidBrush(Color.White);
var myBrushBlack = new StiSolidBrush(Color.Black);
/* Creating report border*/
var myBorder = new StiBorder
{
Color = Color.Black,
Side = StiBorderSides.All,
Size = 1
};
/* Creating report page header*/
var pageHeaderTemplate = new StiPageHeaderBand
{
Height = 2,
Name = "PageHeader",
Brush = myBrush,
Border = myBorder
};
/* Creating text header */
var headerText = new StiText(new RectangleD(20, 20, 4.7, 0.4))
{
HorAlignment = StiTextHorAlignment.Center,
Name = "TextTest",
Text = "teste : {ultimoAcesso}",
Brush = myBrushTransparent,
TextBrush = myBrushBlack,
Border = myBorder,
TextFormat = new StiGeneralFormatService(),
Left = 0.3,
Top = 0.6
};
/* Creating company image logo */
var imageLogo = new StiImage
{
Height = 1.6,
Width = 2.2,
Left = 0.2,
Top = 0.2,
Stretch = true,
Brush = myBrushWhite,
Border = myBorder,
Image = image
};
//create footer
var pagefootertemplate = new StiPageFooterBand
{
Height = 0.5,
Name = "PageFooter",
Brush = myBrush,
Border = myBorder
};
//Create page count on footer
var footerText = new StiText(new RectangleD(0, 0, 7, 0.5))
{
Text = "Página {PageNumber} de {TotalPageCount}",
HorAlignment = StiTextHorAlignment.Left,
Name = "footerPageCount",
Enabled = true,
Brush = myBrush,
Font = new Font("Arial", 12F, FontStyle.Bold)
};
page.Components.AddRange(new StiComponent[]
{
pageHeaderTemplate,
pagefootertemplate
});
pageHeaderTemplate.Components.AddRange(new StiComponent[]
{
imageLogo,
headerText
});
pagefootertemplate.Components.Add(footerText);
return report;
}
I'm trying to create a header and footer throungh runtime with an existing compiled report
but StiText components doesn't show any text after report is printed, my code is rigth below:
private StiReport DesenhaCabecalhoRodape(StiReport report)
{
if (identity == null) return report;
var empresa = _repositoryEmpresa.FindBy<Empresa, Int64>(identity.CompanyId);
var page = report.Pages[0];
/* Creating report page Image*/
var ms = new MemoryStream(empresa.LogoRelatorio);
var image = Image.FromStream(ms);
/* Creating report page Brush*/
var myBrush = new StiSolidBrush(Color.LightGray);
var myBrushTransparent = new StiSolidBrush(Color.Transparent);
var myBrushWhite = new StiSolidBrush(Color.White);
var myBrushBlack = new StiSolidBrush(Color.Black);
/* Creating report border*/
var myBorder = new StiBorder
{
Color = Color.Black,
Side = StiBorderSides.All,
Size = 1
};
/* Creating report page header*/
var pageHeaderTemplate = new StiPageHeaderBand
{
Height = 2,
Name = "PageHeader",
Brush = myBrush,
Border = myBorder
};
/* Creating text header */
var headerText = new StiText(new RectangleD(20, 20, 4.7, 0.4))
{
HorAlignment = StiTextHorAlignment.Center,
Name = "TextTest",
Text = "teste : {ultimoAcesso}",
Brush = myBrushTransparent,
TextBrush = myBrushBlack,
Border = myBorder,
TextFormat = new StiGeneralFormatService(),
Left = 0.3,
Top = 0.6
};
/* Creating company image logo */
var imageLogo = new StiImage
{
Height = 1.6,
Width = 2.2,
Left = 0.2,
Top = 0.2,
Stretch = true,
Brush = myBrushWhite,
Border = myBorder,
Image = image
};
//create footer
var pagefootertemplate = new StiPageFooterBand
{
Height = 0.5,
Name = "PageFooter",
Brush = myBrush,
Border = myBorder
};
//Create page count on footer
var footerText = new StiText(new RectangleD(0, 0, 7, 0.5))
{
Text = "Página {PageNumber} de {TotalPageCount}",
HorAlignment = StiTextHorAlignment.Left,
Name = "footerPageCount",
Enabled = true,
Brush = myBrush,
Font = new Font("Arial", 12F, FontStyle.Bold)
};
page.Components.AddRange(new StiComponent[]
{
pageHeaderTemplate,
pagefootertemplate
});
pageHeaderTemplate.Components.AddRange(new StiComponent[]
{
imageLogo,
headerText
});
pagefootertemplate.Components.Add(footerText);
return report;
}
Wellinton Monge
Re: StiText Component doesn't work correctly
Hello,
I have additional question. You write about compiled report. You want add additional components to compiled report? If yes you should take in consideration that in compiled report all expressions have the compiled status and you can't add expression! You should add event handler. For example:
I'm waiting your response.
Thank you.
I have additional question. You write about compiled report. You want add additional components to compiled report? If yes you should take in consideration that in compiled report all expressions have the compiled status and you can't add expression! You should add event handler. For example:
Code: Select all
var test = new StiText();
test.GetValue += delegate(object sender, StiGetValueEventArgs e)
{
e.Value = "This is sample text";
};
Thank you.
Re: StiText Component doesn't work correctly
Hello Jan,
thanks for the answer... It work fine! Using a delegate event as you showed I feel dumbest programmer ever.
kind regards
thanks for the answer... It work fine! Using a delegate event as you showed I feel dumbest programmer ever.
kind regards
Wellinton Monge
Re: StiText Component doesn't work correctly
Hello,
Glad to help you!
Please contact us if you need any help.
Thank you.
Glad to help you!
Please contact us if you need any help.
Thank you.
Re: StiText Component doesn't work correctly
Hello, Jan I'm facing a problem using event handler bellow... when I need to make "report.pageNofM" inside of it, doens't work. Can you help?
var test = new StiText();
test.GetValue += delegate(object sender, StiGetValueEventArgs e)
{
e.Value = "This is sample text";
};
var test = new StiText();
test.GetValue += delegate(object sender, StiGetValueEventArgs e)
{
e.Value = "This is sample text";
};
Wellinton Monge
Re: StiText Component doesn't work correctly
Hello,
Page numbers are calculated at the end of the render of the report. This approach will not work for the pageNofM.
Thank you.
Page numbers are calculated at the end of the render of the report. This approach will not work for the pageNofM.
Thank you.
Re: StiText Component doesn't work correctly
Hello,
PageNofM its a property of the report object. So you can use following code in event handler:
or
Thank you.
PageNofM its a property of the report object. So you can use following code in event handler:
Code: Select all
e.Value = report.CompiledReport.PageNofM;
Code: Select all
e.Value = ((StiText)sender).Report.PageNofM;
Re: StiText Component doesn't work correctly
Hello, Aleksey I try to add PageNofM at the EndRender of my dynamic report invoking GETVALUE of my component, but didn't work either.
There's any possibility to change value of StiText at de Report EndRender event? Or even a workaround to indicate?
Code: Select all
report.EndRender += delegate (object sender, EventArgs e)
{
var componentFooter = (sender as StiReport).GetComponentByName("stiTextFooter");
(componentFooter as StiText).InvokeGetValue(componentFooter,new StiGetValueEventArgs());
};
Wellinton Monge
Re: StiText Component doesn't work correctly
Hello,
This is a restriction of using named components in the report.
During report rendering exist two instances of each component (minimum two instances).
One instance - component in the report template.
Second instance - component which created for rendered report.
During the creation of the second instance, report engine calculates expressions and write it to the second instance.
The method report.GetComponentByName() return the component from the report template (first instance).
So you assign a value to the instance from the report template, and instances from the rendered report are not changed.
For getting rendered components, you can use the following code, for example:
Thank you.
This is a restriction of using named components in the report.
During report rendering exist two instances of each component (minimum two instances).
One instance - component in the report template.
Second instance - component which created for rendered report.
During the creation of the second instance, report engine calculates expressions and write it to the second instance.
The method report.GetComponentByName() return the component from the report template (first instance).
So you assign a value to the instance from the report template, and instances from the rendered report are not changed.
For getting rendered components, you can use the following code, for example:
Code: Select all
foreach (StiPage page in report.RenderedPages)
{
foreach (StiComponent comp in page.Components)
{
if (comp.Name == "your_component_name")
{
(comp as StiText).InvokeGetValue(comp, new Stimulsoft.Report.Events.StiGetValueEventArgs());
}
}
}
Re: StiText Component doesn't work correctly
Hi there, I still face the same problem, with the solution indicate I reach to the PageNofM with the full text "1 of 20", but when I invoke getvalue of stitext every page print the same value "1 of 20".
Code: Select all
private void EndRenderCustom(object sender, EventArgs e)
{
var rep = sender as StiReport;
for (int i = 0; i < rep.RenderedPages.Count; i++)
{
StiPage page = rep.RenderedPages[i];
for (int j = 0; j < page.Components.Count; j++)
{
StiComponent comp = page.Components[j];
if (comp.Name == "footerPageCount")
{
(comp as StiText).InvokeGetValue(comp, new Stimulsoft.Report.Events.StiGetValueEventArgs());
}
}
}
}
-----------------------------
//* Adding Event To Set de Text Value */
footerText.GetValue += delegate (object sender, StiGetValueEventArgs e)
{
var obj = sender as StiText;
if (obj != null) obj.Text.Value = "Página " + obj.Report.PageNofM;
};
Wellinton Monge