PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Aug 18, 2017 8:12 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Tue Jul 11, 2017 10:28 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
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 275 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 12, 2017 5:43 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 266
Location: CCAA
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).

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 13, 2017 2:52 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 13, 2017 3:09 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2689
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 17, 2017 9:33 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
Yes. We use MigraDoc.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 25, 2017 4:34 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
<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;
        }


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 25, 2017 5:24 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
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;
}


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 25, 2017 9:33 pm 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 266
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 25, 2017 10:01 pm 
Offline

Joined: Tue Jul 11, 2017 10:10 pm
Posts: 6
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?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 26, 2017 8:21 am 
Offline
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 266
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], williams3, Yahoo [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group