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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Pdf Keep Rows together

Thread ID:

Created:

Updated:

Platform:

Replies:

130150 Apr 25,2017 11:54 AM UTC May 2,2017 09:44 AM UTC ASP.NET Web Forms 7
loading
Tags: PDF
Matt Tracey
Asked On April 25, 2017 11:54 AM UTC

Hi,
I'm creating a pdf and adding a PdfGrid. In the PDF grid I need to keep certain rows together on the same
page. So if the, say, 2 rows didn't fit at the end of a page they would be printed on the next page.

I have previously used PDFSharp which had a "KeepWith" property on a table row to specify blocks that 
must be kept together. I can't find a similar keepwith property and was wondering is there one?

I've attached a project that prints a PdfGrid - in it there are two rows ( row part 1, row part 2) that need to be kept on
the same page. If "
row part 1" is at the bottom of a page and "row part 2" is going to be printed on the next page,
then "
row part 1" and "row part 2" both need to be printed on the next page.

Thanks in advance,
Matt

Attachment: PdfGridTable_3a593728.7z

Surya Kumar [Syncfusion]
Replied On April 27, 2017 12:58 PM UTC

Hi Matt,  

Thank you for using Syncfusion products, 

We do not have support for Keeping multiple set of PdfGrid rows together in a page, but we can fit individual element (PdfGrid rows) within a page with the help of code snippet below: 

            //Setting Layout format for the PdfGrid 
            PdfGridLayoutFormat format = new PdfGridLayoutFormat(); 
            format.Break = PdfLayoutBreakType.FitElement; 
 
            //Draws grid to the page of PDF document with speified format. 
            pdfGrid.Draw(page, new PointF(10, 10), format); 

Please find the screenshot for the moved Grid row element to the next page in case if there is lack of space for drawing the next row: 
 


Please let us know if you need any further information regarding this. 

Regards, 
Surya Kumar 


Matt Tracey
Replied On April 28, 2017 09:19 AM UTC

Thanks for your help - I'll try that,
Cheers,
Matt

Surya Kumar [Syncfusion]
Replied On May 1, 2017 06:58 AM UTC

Hi Matt,   
 
Thanks for the update, we will wait to hear from you. 
 
Regards, 
Surya Kumar 


Emi Lee
Replied On May 1, 2017 09:31 AM UTC

Thanks for update http://help4assignment.co.uk

Matt Tracey
Replied On May 1, 2017 09:51 AM UTC

Hi,
I was unable to use FitElement to get it working - I had 2+ rows to keep together.

What I ended up doing was adding just one row to the datatable for each of the "rows" I had and using "\r\n" to put the next virtual "row"
on a new line:
Example:
     string lcCol0 = "Row 1 Col 1 Text";
     string lcCol1 = "Row 1 Col 2 Text";

     lcCol0 += "\r\n" + "Row 2 Col 1 Text";
     lcCol1 += "\r\n" + "Row 2 Col 2 Text";

     lcCol0 += "\r\n" + "Row 3 Col 1 Text";
     lcCol1 += "\r\n" + "Row 3 Col 2 Text";

     DataTable loTableData = new DataTable();
     loTableData.Columns.Add("Col1");
     loTableData.Columns.Add("Col2");
     loTableData.Rows.Add(new string[] { lcCol0, lcCol1 } );

Then for the Grid I used a BeginCellLayout:
     PdfGrid moGrid = new PdfGrid();
     moGrid.DataSource = loTableData;
     moGrid.BeginCellLayout += moGrid_BeginCellLayout;

The benefit of this was I was able to bold certain strings within the text using BeginCellLayout and PdfHTMLTextElement,
It also allowed me to draw a border at the top and using BeginCellLayout I had to fudge the border - It was too close to the top.

Below is my BeginCellLayout for my specific need, I only needed to do it for col 6:

private static PdfFont moFont10 = new PdfTrueTypeFont(new Font("Calibri", 10), true);

public static void moGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
            PdfHTMLTextElement textElement = new PdfHTMLTextElement();
            textElement.Font = moFont10;

            if (args.CellIndex == 6)
            {
                if (args.Value != "Event category, Consequence and event description")
                {
                    float lnX = args.Bounds.X;
                    float lnY = args.Bounds.Y;
                    float lnL = args.Bounds.Left;
                    float lnT = args.Bounds.Top;
                    float lnW = args.Bounds.Width;
                    float lnH = args.Bounds.Bottom;

                    args.Skip = true;
                    textElement.HTMLText = args.Value;
                    args.Graphics.DrawRectangle(PdfPens.Black, lnL, lnT + 1, lnW, 0);
                    textElement.Draw(args.Graphics, new RectangleF(lnX, lnY+4, lnW, lnH + 4));
                    
                }
            }
}

There was one little gotcha in the BeginCellLayout when I moved the textElement down by "4" the end of the text
moved down as well, so in the Col6 in the datatable I had to append 
"\r\n" + "\r\n" at the end of a text.

Anyway - It works and the plus is it allows me to use HTML formatting in the text.

Thanks again for your help - just leaving this update in case anyone needs a similar solution.

Cheers,
Matt

Matt Tracey
Replied On May 1, 2017 09:55 AM UTC

BTW - just an addendum:
I also used the FitElement that was suggested before and this made sure the rows stayed on new pages if the
rows are too big.

Cheers,
Matt

Prakash Viswanathan [Syncfusion]
Replied On May 2, 2017 09:44 AM UTC

Hi Matt, 
 
Thanks for your update. 
Please let us know if you need any further assistance on this. 
 
Regards, 
Prakash V 


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

;