We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

pdf grid row height auto adjust

Thread ID:

Created:

Updated:

Platform:

Replies:

119192 May 20,2015 03:03 PM UTC Jul 23,2015 10:31 AM UTC Windows Forms 6
loading
Tags: PDF
jb
Asked On May 20, 2015 03:03 PM UTC

Is there a way to adjust the grid row height based on length of text that is assigned to a grid cell?

jb
Replied On May 20, 2015 08:36 PM UTC

Is there a way to adjust the grid row height based on length of text that is assigned to a grid cell?

I am using MeasureString method of a PDfFont instance to get the size and using that to set thr pdfgrid row height.

In some cases, the string of `asdalksjdakldhajlhskjdfhasljfaskldjfaskldfjaskldfjsklajklsmdfsdmn`

the cell width = 362 and height is 14

Using a specific font and style, the measure string returns height of 7 , which does not work


what is the best way to caluclate the string dimension and adjust the pdfgrid row height

Chinnu Muniyappan [Syncfusion]
Replied On May 21, 2015 02:10 PM UTC

Hi Jp,
 
Thanks for using syncfusion product,

We have created the sample to calculate the string height and also adjusted the pdfGrid height with the string height, Please try the sample in your environment and let us know if you found any issue.
PdfGridIssues.zip

 

Thanks,

Chinnu



jb
Replied On May 26, 2015 04:00 PM UTC

Hi Jp,
 
Thanks for using syncfusion product,

We have created the sample to calculate the string height and also adjusted the pdfGrid height with the string height, Please try the sample in your environment and let us know if you found any issue.
PdfGridIssues.zip

 

Thanks,

Chinnu



thanks for the solution. however it does not give the correct height. modifying your code as below, you will observe that the height is not adjusted correctly

private void Form1_Load(object sender, EventArgs e)
        {
            //create a new pdf document
            PdfDocument doc = new PdfDocument();

            //create new page
            PdfPage page = doc.Pages.Add();

            Font ffont = new Font("Arial", 6, FontStyle.Regular);

            //create a new pdf font
            PdfFont font = new PdfTrueTypeFont(ffont,true);

            //create a pdfgrid
            PdfGrid grid = new PdfGrid();

            //add new row to grid
            grid.Rows.Add();

            //add new column to grid
            grid.Columns.Add(10);

            PdfGridCellStyle style = new PdfGridCellStyle();
            style.Font = font;
            grid.Rows[0].Cells[0].Style = style;

            

            //measure the string height
            SizeF size = font.MeasureString("Toto jeřetězec, který sycnfusion státy by změna velikosti");

        
            grid.Rows[0].Height = size.Height + 1;
           
            
            //set the text to grid cell
            grid.Rows[0].Cells[0].Value = "Toto jeřetězec, který sycnfusion státy by změna velikosti";

            //draw the grid to pdf
            grid.Draw(page, PointF.Empty);

            //save the pdf document
            doc.Save("Pdfgrid.pdf");

            //close the document
            doc.Close(true);
            
        }

any other ideas?

Chinnu Muniyappan [Syncfusion]
Replied On May 27, 2015 12:49 PM UTC

Hi Jp,

 

We have changed the sample as per your requirement, and also paste the code snippet for your reference. Please try this sample and let us know if you have any concern.

 

  • Here we have calculated the column width as default to calculate the height of the PdfGrid row. You can also set the column width manually and calculate the height based on that width.

            //Get total width of the page

            float pagewidth = page.GetClientSize().Width;

           //divide the grid column count to page width now get a single column width

            float columnWidth = pagewidth /= numberOfColumn;

            //divide the text width and column width

            float lineCount = (size.Width / columnWidth)+1;

            //set the row height

            grid.Rows[0].Height = ((size.Height+1) * lineCount;

 

  • In the second page of the generated PDF, we have created a CheckFontMeasuredString method to check the measured string value is correct or not. I have attached the output PDF document generated from our side; if you found any difference please provide us the PDF document generated from your side.

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/PdfGridIssues1676239076.zip
 
Thanks,
Chinnu



jb
Replied On July 22, 2015 01:27 PM UTC

Used your code and noticed that there is padding on the text on page 1. Page 2 of your sample shows correct rendering and no Left and Right padding.

Change the # of columns to 14 and on Cell[0] the text will be rendered but with some padding on top and bottom




Chinnu Muniyappan [Syncfusion]
Replied On July 23, 2015 10:31 AM UTC

Hi Jp,
Thanks for your update.
I am afraid that I am not able to reproduce the reported issue. I have attached the working sample for your reference could you please modify the sample to reproduce the issue so that we will analyse in this and provide you the solution at the earliest.
Sample Link:
http://www.syncfusion.com/downloads/support/forum/119192/ze/PdfGridIssues1147304709
Regards,
Chinnu

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;