itextSharp: Table disappears when added to Paragraph with KeepTogether=true - c#

I am exporting some data to a PDF and I have been using iTextSharp with a lot of success, but I just hit a wall.
I have a group of information I need to keep on a single page. This information includes a handful of other Paragraph objects and tables. I can add 3 Paragraphs to another parent Paragraph and set that parent's KeepTogether property to true and everything works great.
When I add a PdfPTable to the Paragraph with KeepTogether set to true, the table disappears. No Exceptions or error messages, the table just disappears.
Any clue as to what is happening? Is there a work around? Should I be coding differently, like is there a better parent control than Paragraph to keep text and tables together on one page?

So I fixed the issue by approaching it a different way. Now I make sure to never set a KeepTogether property to true for paragraphs or tables.
Then, when I want a Paragraph that contains child paragraphs and PdfPTables, I add it to a one column, one cell, PdfPTable with its KeepTogether flag set to true.
So that works perfectly, just a little dirty.

Related

Multi page section with title on every page in MigraDoc

I want a document with multiple pages. Every page should have the same header. One section of the document contains a long table, which stretches over multiple pages. On every page of this section I want to show a title above the table.
I came up with two solutions so far. Both seem hacky and have their downsides:
Make the title part of the header in this section. Feels wrong and is also annoying when I have other pages in the document which should contain the header but not the title.
Make the title part of the table and use HeadingFormat. Feels hacky as well because the title doesn't "fit" in the columns of the table.
Any better ideas?
Re 1: Put the table in a new section and set a new header for that section. One line can be the standard header shared by all pages, another line can be a special header for the table section.
Does not look hacky to me.
Re 2: You can set the HeadingFormat for several rows. So you can use the first row for the "header" without any border and with a MergeRight so it spans the whole page. Not really hacky and will look like normal text outside the table.
Solution 1 has a downside as every new section starts on a new page. Well, the table is so important that it even gets an own page header, so this downside should not matter.
A hacky and tricky solution would be using PDFsharp to add a special header on all pages with the table on it. I think I'd go for option 2.

What are the best ways to deal with these PDFSharp table limitations?

I am using PDFSharp to export a table to PDF (using the regular MigraDoc.DocumentObjectModel.Tables.Table object). It works great except I ran into a few issues:
if the content of a single cell in the table is longer than the height of the page it seems like the content just gets cut off. A table itself can span multiple pages but a row seems like it can only be 1 page high and It seems like it doesn't extend onto the next page.
Is there any workaround to this or is this just a bug in the library?
Also for tables that span multiple pages, is there a way to have the header row on the table show up at the top of every page?
Re first question:
It's documented that MigraDoc does not break table rows over multiple pages. It's not a bug, it's a limitation. So it's up to you to design the tables that this does not cause problems.
IIRC there is a hack published on the PDFsharp forum that increases the page height to work around this problem. If you only need PDFfiles, this could be a workaround.
Edit: Didn't find the link when I made the post, but found it today when I tried again: Here's the workaround:
http://forum.pdfsharp.net/viewtopic.php?p=4311#p4311
I didn't try it myself.
Re second question:
Rows marked as header rows will be repeated on every new page. Just set the HeadingFormat property of those rows to true.

ObjectListView doesn't word-wrap

I am using ObjectListView instead of the standard ListView is because I wanted to word-wrap the columns.
I read in several places that the only thing I need to to in order to enable word-wrapping is the set column.wordWrap to true.
I did just that, but it doesn't work.
What am I missing here?
Edit:
I realise now that I need to make my column owner drawn.
I found this page which sort of tells me what to do, but I'm not sure where to place it in my code. I'm also not quite sure whether I need to add certain attributes inside the delegate to allow word-wrapping (by the looks opf things it's enabled by default). The thing is, I tried what I found in this page, copied it word for word, and my list looks exactly the same...
If you mean by "word wrapping", you want different rows to have different heights, the FAQ answer is correct -- it simply can't be done.
However, if you make each row so that it can display two or more lines of text, then, yes, ObjectListView can word wrap.
It needs three conditions:
Set WordWrap to true on the column to wrap. You've already done that.
Make sure the ObjectListView is owner drawn (set OwnerDraw to true -- this can be done in the Form Designer). The base ListView can't word wrap, so we have to draw the cells ourself.
Make sure there is room to see the wrapped lines by setting the RowHeight to 32 (or some other value)
This is the data tab from the demo. The first column has WordWrap set to true.
On the ObjectListView SourceForge FAQ page, it explicitly states:
Can it word-wrap?
No.

Paragraph breakage, one page to the other page, in detail section of Crystal Reports

I have made a report in Crystal Reports, it has a detail section, i have dragged a variable carrying text and if the paragraph of the text longer, i want its half of the part should be gone to the next page, as we see in text books and as it is a standward way on A4 paper.
When i write a variable carrying data in text for detail, this problem occurs. I had used some algorithm or like that to divide the data into two parts and made two variables, but as data can be html also so that algorithm does not work in very good manner. I just want to use crystal reports functionality. Thanks in advance.I am attaching an image for further understanding.
The history field should have a property called 'keep together'. I'm guessing its set to true and should be changed to false to allow the field to be split across a page break.

remove unwanted space in header/footer

I'm currently writing a program in C# that programmatically insert table in header/footer for MSWORD 2003.
My problem is after creation of table, there is unwanted space after the table. I have already manually fix or delete it using msword, but I cannot remove that extra space. Because of that the cursor was not start where the point of top margin is.
I've already google it but cannot find any solution. Any help will appreciate. Tnx
You can also set the Text Wrapping property of the table to AROUND instead of NONE. this will cause the following para mark to float to the right of the table, not below it, so you won't get the extra line, and you won't have to resort to 1 pt hacks (which work, but I try to avoid them when possible).
It's easy to do in Word manually, but A quick try at recording a macro to do it failed so I'm not sure of the Object Model method.
By default there is a new line after a table in MS Word. As a workaround you could try to set the font size after the table to 1.

Categories