I'm trying to use Documents Reports and seem to be having some basic problems (or just things that I don't understand yet.
For example. I'm trying to set the height of the report header. I've got a header with an image and then n-lines of text. The text can be variable in length and number of lines. What I'd like to be able to do is to use the various "Addxxx" methods and either have the height calculated based on the content or give me some method of getting the resulting height. This does not seem to be available or I'm missing something basic.
I've also got a grid with multiple columns. I want to set the width of the first column based on the widest text in the column cells. Again, I'd like to have the grid figure that out for me similar to what I can have the UltraGrid do for me with autoresize. Instead, I tried the following
Infragistics.Documents.Report.Text.Style boldStyle = new Infragistics.Documents.Report.Text.Style( new Infragistics.Documents.Graphics.Font("Verdana", 8, Infragistics.Documents.Graphics.FontStyle.Normal), Infragistics.Documents.Graphics.Brushes.Black);
//* Since I don't seem to be able to get to the base font from the style I did
Font textFont = new Font(normalStyle.Font.Name, normalStyle.Font.Size, FontStyle.Regular);
//Then, loop over the text and try to get the width
Int32 maxColumnWidth = 0;
Size cellSize;Size proposedSize = new Size(int.MaxValue, int.MaxValue);TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; //TextFormatFlags.GlyphOverhangPadding | TextFormatFlags.Left | TextFormatFlags.ExternalLeading | TextFormatFlags.WordBreak; foreach ( String thing in _myListOfThings )
{
String newThing = thing.Replace("<br/>", System.Environment.NewLine); cellSize = TextRenderer.MeasureText(newThing, textFont, proposedSize, flags); maxColumnWidth = Math.Max(tastableColumnWidth, cellSize.Width);
}
textFont.Dispose();
gridColumn = grid.AddColumn();gridColumn.Width = new Infragistics.Documents.Report.FixedWidth((float) maxColumnWidth);
This does calculate something that looks reasonable but when I get the exported PDF result the first column is about 40% wider than what I think I calculated in the above.
In any case, is there something I'm missing here that would make Reports more usable?
Thanks
In theory, the AutoHeight automatically calculates the required height when the report is published. So you do not need to set the height.
Of course, nothing is ever really that simple, and there may be other factors at work here. To be honest, I've had some difficulty with AutoHeight - sometimes it doesn't behave the way I expect it to, and the reasons for this are not always obvious.
If AutoHeight is not working for you, you could report it to Infraistics Developer Support and see if they can figure out why. Submit a Support Issue
Alternately, if you want to calculate the height yourself, you would use a FixedHeight instead of an AutoHeight. With a FixedHeight, you can pass the height you want into the constructor. Which then, of course, brings you back around to the original problem of what height to use. There's no exposed way to measure strings in the report. So you would have to do what the grid does - determine the size of the text as it would be on-screen using methods like MeasureString, and then convert pixels into points.
I'm not exporting a grid I'm buiding a grid from other data. My "like..." comment was just an example of the autosize I was looking for.
In the response from Matt above he suggests using AutoHeight on the header but I'm not sure exactly how to use an autoheight instance here.
I tried
Infragistics.Documents.Report.Section.ISectionHeader sectionHeader = section.AddHeader();
sectionHeader.Height = Infragistics.Documents.Report.AutoHeight.Instance
but (of course) this returns an autoheight class and can't be assigned to the height property of the header so I'm not sure how to use this to make sure that the header is sized automatically.
Neil
Hi Neil,
I'm not really clear on what you are doing here. If you are exporting a grid to a PDF, then the AutoSize property on the UltraGridDocumentExporter will take care of autosizing the column for you.
If you are trying to do this manually for some reason, then you could AutoSize the grid column to the contents by simply calling the PerformAutoResize method on the column. You don't have to loop.
The only tricky thing is that the grid column will size based on the scale mode of the screen (pixels) and the PDF document works with points. So you would have to convert pixels to points. There's a static utility method to do this:
Infragistics.Win.UltraWinGrid.DocumentExport.Utilities.PixelsToPoints
Neil,
For your first issue with the sizing of the headers, does setting the height to Infragistics.Documents.Report.AutoHeight.Instance work for you? That should size the header to the content.
As for your second issue, the reason that the size you're getting is wider than what is actualy measure is that PDF units are in Points, not Pixels. Fortunately, there's a public method already exposed that you can use:
float width = Infragistics.Documents.Utils.Converter.PixelsToPoints(maxColumnWidth);
gridColumn.Width = new Infragistics.Documents.Report.FixedWidth(width);
-Matt