Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing report font dynamically (Java)

Status
Not open for further replies.

pheynman

Programmer
Mar 12, 2009
8
0
0
US
Hi,

I was wondering if anybody had had to change report fonts dynamically depending on what the user would like to use. Does it depend on the report definition being defined to accept variables like:
Code:
[COLOR=blue]If[/color] {?NewFont} <> [COLOR=red]""[/color] [COLOR=blue]Then[/color]
    {?NewFont}
[COLOR=blue]Else[/color]
    [COLOR=blue]DefaultAttribute[/color]
or can you just wrire code against it and call the crystal report viewer?

This is what I have (briefly):
Code:
	[COLOR=purple]private void[/color] ChangeFont(IEnterpriseSession enterpriseSession, IInfoObject report) [COLOR=purple]throws[/color] SDKException, ReportSDKException
	{
		IReportAppFactory reportFactory = (IReportAppFactory) enterpriseSession.getService("RASReportFactory");
		ReportClientDocument reportClientDocument = reportFactory.openDocument(report, 0, Locale.getDefault());
		ReportObjectController reportObjectController = reportClientDocument.getReportDefController().getReportObjectController();
		ReportObjects reportObjects = reportObjectController.getReportObjectsByKind(ReportObjectKind.text);

		IFontColor newFontColor = getFontColor();

		[COLOR=purple]if[/color] (reportObjects != [COLOR=purple]null[/color] && !reportObjects.isEmpty())
		{
			[COLOR=purple]for[/color] ([COLOR=purple]int[/color] i = 0; i < reportObjects.size(); i++)
			{
				IReportObject reportObject = reportObjects.getReportObject(i);
				[COLOR=purple]if[/color] (reportObject instanceof ITextObject)
				{
					ITextObject textObject = (ITextObject) reportObject;
					IFontColor fontColor = textObject.getFontColor();
					fontColor = newFontColor;
					textObject.setFontColor(fontColor);					
				}
			}
		}
		
		reportObjects = reportObjectController.getReportObjectsByKind(ReportObjectKind.field);

		[COLOR=purple]if[/color] (reportObjects != [COLOR=purple]null[/color] && !reportObjects.isEmpty())
		{
			[COLOR=purple]for[/color] ([COLOR=purple]int[/color] i = 0; i < reportObjects.size(); i++)
			{
				IReportObject reportObject = reportObjects.getReportObject(i);
				[COLOR=purple]if[/color] (reportObject [COLOR=purple]instanceof[/color] IFieldObject)
				{
					IFieldObject fieldObject = (IFieldObject) reportObject;	
					IFontColor fontColor = fieldObject.getFontColor();
					fontColor = newFontColor;
					fieldObject.setFontColor(fontColor);
				}
			}
		}
	}

There may be a lot wrong with the code but for now, I'm focusing on the stuff that could enable the changes. I tried this code with the way the viewer is currently set up. This viewer is custom; not the com.crystaldecisions.report.web.viewer.CrystalReportViewer which is what I'm now trying to use (and have not finished coding):

Code:
com.crystaldecisions.report.web.viewer.CrystalReportViewer vwr = new com.crystaldecisions.report.web.viewer.CrystalReportViewer();
vwr.processHttpRequest(_request, _response, getServletContext(), [COLOR=purple]null[/color]);
vwr.setHasExportButton(true);
vwr.setDisplayGroupTree(true);
vwr.setReportSource(report);
vwr.setDisplayPage(true);

Any help in the right direction (beyond just a link to the SDKs which I'm working through) would be appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top