PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Text is being truncated in paragraph if the text is too big
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3624
Page 1 of 1

Author:  ecxiao [ Tue Jul 11, 2017 10:28 pm ]
Post subject:  Text is being truncated in paragraph if the text is too big

When the text is too long, it cut off the remaining of the content of page 2 and not continue on page 3.

Attachments:
Screen Shot.jpg
Screen Shot.jpg [ 245.8 KiB | Viewed 9475 times ]

Author:  TH-Soft [ Wed Jul 12, 2017 5:43 am ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

Hi!
ecxiao wrote:
When the text is too long, it cut off the remaining of the content of page 2 and not continue on page 3.
This happens when you do things the wrong way.
No code, no MDDDL, not even basic information (click the blue words "Forum Rules" in the orange box on the top of this page).

Author:  ecxiao [ Thu Jul 13, 2017 2:52 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

Sorry. I am new to this product. And I am taking of it for supporting in my company in just a couple days. I will try to gather information and update here.

When I posted it with very basic description, I though you might have seen this issue before and will be able to quickly direct me to the right place to discover the issue.

Author:  Thomas Hoevel [ Thu Jul 13, 2017 3:09 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

Hi!

It is a known limitation that table cells do not break across pages. Do you use a Table?
Paragraphs break across pages until you mark them as KeepTogether.
Maybe there are other ways to get that effect. It's not really obvious from just a screen shot.
And I'm just assuming the document was made with MigraDoc.

Author:  ecxiao [ Mon Jul 17, 2017 9:33 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

Yes. We use MigraDoc.

I am on vacation this week, and I will submit the code next week by Tuesday. Thanks.

Author:  ecxiao [ Tue Jul 25, 2017 4:34 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

<package id="PDFsharp-MigraDoc-GDI" version="1.32.4334.0" targetFramework="net451" />

Code:
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;

public Document CreateReport(BaseReportModel model, bool isPreview)
        {
            var document = new Document();
            document.Info.Title = "{0} for {1}".FormatWith(model.ReportType, model.StudentName);
            document.Info.Subject = model.ReportType.Name;
            document.Info.Author = "xxxxxxxxxxxxxx";

            SetUpMargins(document);
            SetupReportStyles(document);

            var mainSection = document.AddSection();
            if (isPreview) AddDraftWatermarkToSection(mainSection);

            AddFooter(mainSection, model.ReportType.Name, model.StudentName, model.StudentNumber);
            AddReportHeader(mainSection, model);
            AddGeneralInformationSection(mainSection, model);
            AddProgramSection(mainSection, model);

            var backGroundColor = ReportFormatting.BlueBackgroundColor;
            if (isPreview) backGroundColor = ReportFormatting.BlueBackgroundColorWithTransparency;

            var numberOfVisibleSections = 0;
            if (model.ConditionsForSuccessItems.Count > 0)
            {
                AddConditionsForSuccessSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
                numberOfVisibleSections++;
            }
            if (model.CurrentLearningsItems.Count > 0)
            {
                AddCurrentLearningSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
                numberOfVisibleSections++;
            }
            if (model.PriorityLearningCyclesItems.Count > 0)
            {
                AddPriorityLearningAreasSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
                numberOfVisibleSections++;
            }
            if (model.SpecializedAssessmentsItems.Count > 0)
            {
                AddSpecializedAssessmentsSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
                numberOfVisibleSections++;
            }
            if (model.KeyUnderstandingsItems.Count > 0)
            {
                AddKeyUnderstandingsSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
                numberOfVisibleSections++;
            }
            if (model.SupportsAndServicesItems.Count > 0)
            {
                AddSupportAndServicesSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
            }

            return document;
        }
    }

protected static void AddCurrentLearningSection(Section section, BaseReportModel reportData, Color backgroundColor)
        {
            var table = CreateLearnerProfileSectionTable(section, backgroundColor);
            table.AddColumn("1.0cm");
            table.AddColumn("1.0cm");
            table.AddColumn("16.0cm");

            AddLearnerProfileSectionHeader(table, "Current Learning");

            if (reportData.CurrentLearningsItems.Count == 0)
            {
                AddNoContentMessage(table);
            }
            else
            {
                foreach (var model in reportData.CurrentLearningsItems.OfType<CurrentLearningModel>())
                {
                    AddCurrentLearningModel(table, model);
                }
            }

            AddSectionBorderRow(table);
        }

private static Table CreateLearnerProfileSectionTable(Section section, Color backgroundColor)
        {
            var table = section.AddTable();
            table.Shading.Color = backgroundColor;
            table.Borders.Visible = false;
            table.Borders.Width = 0;
            table.Borders.Style = BorderStyle.None;
            table.Format.KeepTogether = true;
            table.BottomPadding = 0;
            table.KeepTogether = true;

            return table;
        }

private static void AddLearnerProfileSectionHeader(Table table, string heading)
        {
            var row = table.AddRow();
            row.Borders.Top.Color = ReportFormatting.BlueBorderColor;
            row.Borders.Top.Visible = true;
            row.Borders.Top.Width = 1;

            row = table.AddRow();
            var cell = row.Cells[0];
            cell.MergeRight = cell.Table.Columns.Count - 1;
            cell.Row.KeepWith = 2;
            var paragraph = cell.AddParagraph();
            paragraph.Format.KeepTogether = true;
            paragraph.Format.KeepWithNext = true;
            paragraph.AddFormattedText(heading, ReportFormatting.LargeBlueHeading);
        }

private static void AddCurrentLearningModel(Table table, CurrentLearningModel model)
        {
            var row = GetDefaultHeadingRow(table, model.Content, TextFormat.NotBold);
            row.Cells[1].MergeRight = 1;

            if (!model.HideTags)
            {
                if (model.Tags.Count > 0)
                {
                    foreach (var tag in model.Tags)
                    {
                        row = table.AddRow();
                        row.KeepWith = 1;
                        var paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText(tag.Text, ReportFormatting.CurrentLearningTagText);
                    }
                }
            }

            row.BottomPadding = DefaultBottomPadding;

            AddModifiedByLineToParagraph(table, 1, 1, model);
        }

private static Row GetDefaultHeadingRow(Table table, string title, TextFormat textFormat = TextFormat.Bold)
        {
            var row = table.AddRow();
            row.BottomPadding = DefaultBottomPadding;
            row.TopPadding = DefaultTopPadding;
            row.KeepWith = 1;

            var paragraph = row.Cells[1].AddParagraph();
            paragraph.AddFormattedText(title, textFormat);

            return row;
        }

 private static void AddModifiedByLineToParagraph(Table table, int cellIndex, int numberOfCellsToMergeRight, BaseReportItemModel model)
        {
            if (model.HideAuthorAndDate)
            {
                table.Rows[table.Rows.Count - 1].KeepWith = 0;
                return;
            }

            var row = table.AddRow();
            var paragraph = row.Cells[cellIndex].AddParagraph();
            row.Cells[cellIndex].MergeRight = numberOfCellsToMergeRight;
            paragraph.AddFormattedText(string.Format("{0} | {1}", model.ModifiedDate, model.ModifiedBy), ReportFormatting.SmallPrint);
        }

private static void AddSectionBorderRow(Table table)
        {
            var row = table.AddRow();
            row.Borders.Bottom.Color = ReportFormatting.BlueBorderColor;
            row.Borders.Bottom.Width = 1;
            row.Borders.Bottom.Visible = true;
        }

Author:  ecxiao [ Tue Jul 25, 2017 5:24 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

I added 2 keeptogether into the 2 places of paragraph which were not specified before, but I still get the same result. How to extend the long text of a table into next page is what I want to achieve. Please help. URGENT!!!

private static void AddCurrentLearningModel(Table table, CurrentLearningModel model)
{
var row = GetDefaultHeadingRow(table, model.Content, TextFormat.NotBold);
row.Cells[1].MergeRight = 1;

if (!model.HideTags)
{
if (model.Tags.Count > 0)
{
foreach (var tag in model.Tags)
{
row = table.AddRow();
row.KeepWith = 1;
var paragraph = row.Cells[2].AddParagraph();
//Echo
paragraph.Format.KeepTogether = true;

paragraph.AddFormattedText(tag.Text, ReportFormatting.CurrentLearningTagText);
}
}
}

row.BottomPadding = DefaultBottomPadding;

AddModifiedByLineToParagraph(table, 1, 1, model);
}

private static Row GetDefaultHeadingRow(Table table, string title, TextFormat textFormat = TextFormat.Bold)
{
var row = table.AddRow();
row.BottomPadding = DefaultBottomPadding;
row.TopPadding = DefaultTopPadding;
row.KeepWith = 1;

var paragraph = row.Cells[1].AddParagraph();
//Echo
paragraph.Format.KeepTogether = true;

paragraph.AddFormattedText(title, textFormat);

return row;
}

Author:  TH-Soft [ Tue Jul 25, 2017 9:33 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

ecxiao wrote:
I added 2 keeptogether into the 2 places of paragraph which were not specified before, but I still get the same result.
KeepTogether does not break text, it keeps it together.

ecxiao wrote:
How to extend the long text of a table into next page is what I want to achieve. Please help. URGENT!!!
As written in post #4, tables break between rows. Rows are kept together on one page, so make sure you do not have too much text in each row.
Maybe use paragraphs with border/background colour instead of the Table.
Maybe create more rows with shorter text each.

Author:  ecxiao [ Tue Jul 25, 2017 10:01 pm ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

ecxiao wrote:
Maybe use paragraphs with border/background colour instead of the Table.

Can you give an example on how to do it? Have you look at the code I posted?

ecxiao wrote:
Maybe create more rows with shorter text each.

When user submits a long text, it is impossible to know where to break it into next row.

Do you know what is the max. text you usually suggest in a table row on one page?

Author:  TH-Soft [ Wed Jul 26, 2017 8:21 am ]
Post subject:  Re: Text is being truncated in paragraph if the text is too

ecxiao wrote:
Have you look at the code I posted?
Yes. Not easy to read. Lots of lines, but still just a code snippet.

ecxiao wrote:
Do you know what is the max. text you usually suggest in a table row on one page?
That text that fits onto one page depends on page size, column width, font size, ...

See the "DemonstrateBordersAndShading" method with this sample:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
No tables, no problems with page breaks.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/