Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
Calculating Element Sizes
posted

 

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

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

     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     

Children