PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jun 29, 2024 7:42 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Mar 04, 2014 10:48 am 
Offline

Joined: Tue Jan 14, 2014 10:30 am
Posts: 6
Hi,

This question is asked already several times in this forum, but for most of them there is no answer or the proposed answers don't work or not in my case.
(viewtopic.php?f=2&t=1073, viewtopic.php?f=2&t=265&start=0 (at the end), viewtopic.php?f=2&t=518 (also at the end))

I'm using Migradoc version 1.32.4334.0, normally the latest version from NuGet.

I have a table with a title. This title is not the header of the table!
The title is putted in a paragraph and the table is inserted after the paragraph.

When page breaking occurs, I want to keep the title and the table together. If the table is long, it can break itself over several pages. That is not the problem, the table headers are repeated each page.
But the first time the table is printed, I want to keep the title and table together to avoid that the title of de table is on page X and the table itself is on page X+1.

I tried the options KeepTogether and KeepWithNext of the paragraph, but they only work if another paragraph is following, not a table.

So, what are my options here?


Attachments:
File comment: Example of title and table not on one page
migradoc title and table not on one page.png
migradoc title and table not on one page.png [ 30.86 KiB | Viewed 11934 times ]
Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 10:59 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
evb wrote:
I tried the options KeepTogether and KeepWithNext of the paragraph, but they only work if another paragraph is following, not a table.
That's the problem: it doesn't work currently as I think it should.

evb wrote:
So, what are my options here?
The simple solution: add a page break before the header.

Or use a hack: add the header, call "docRenderer.PrepareDocument();" and store the page count. Add the table with e.g. 3 or 4 rows and call "docRenderer.PrepareDocument();" again. If the page count has changed, add page break before the header. Finally add the remaining table rows.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 1:25 pm 
Offline

Joined: Tue Jan 14, 2014 10:30 am
Posts: 6
How to add a pagebreak before the title after checking the pagecount in the table?

Code:
            // if I add here a pagebreak then it works, but this a hardcoded always set addpagebreak
            // sec.AddPageBreak();
            Paragraph para = sec.AddParagraph();
            para.AddFormattedText(CoreResources.Strings.ListGlobalCriteria, TextFormat.Bold | TextFormat.Italic).Style = "Label";
            para.Format.SpaceAfter = 2;

            Table tableCriteria = sec.AddTable();
            tableCriteria.AddColumn(50);
            tableCriteria.AddColumn(50);
            Row rowCriteria = tableCriteria.AddRow();
            rowCriteria.HeadingFormat = true;
            ...
            // hack to keep together paragraph and table
            DocumentRenderer docRenderer = new DocumentRenderer(document);
            docRenderer.PrepareDocument();
            int pageCountAfterHeader = docRenderer.FormattedDocument.PageCount;


            rowCriteria = tableCriteria.AddRow();
            ....
            rowCriteria = tableCriteria.AddRow();
            ....
            rowCriteria = tableCriteria.AddRow();
            ....
           
            docRenderer.PrepareDocument();
            int pageCountAfterRow = docRenderer.FormattedDocument.PageCount;
            if (pageCountAfterRow > pageCountAfterHeader)
                        sec.AddPageBreak();   ???? but how can I put here a page break before my paragraph title?


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 04, 2014 3:14 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Untested code (there may be typos, but I hope you get the idea):
Code:
int idx = section.Elements.IndexOf(para);
section.Elements.InsertObject(idx, new PageBreak());

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 7:43 am 
Offline

Joined: Tue Jan 14, 2014 10:30 am
Posts: 6
Ok, it is working.

Code:
int idx = sec.Elements.IndexOf(para);
sec.Elements.InsertObject(idx, new PageBreak());


Thanks


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 05, 2014 12:05 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Sorry, I forgot Elements. :oops:
Glad to see you figured it out.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 13, 2015 3:36 pm 
Offline

Joined: Tue Jan 13, 2015 3:33 pm
Posts: 10
Hello,

I am having the same problem.
Is there a bugfix for the problem by now? So is there an easier (or less hacky) way to keep a paragraph and a table together?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 13, 2015 3:44 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
The bug was fixed with MigraDoc 1.50 beta.
See also:
viewtopic.php?f=1&t=3017

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group