Migradoc: Adding pagebreaks when within certain distance of end of page - c#

I'm trying to generate a report using Migradoc. The general generation of the PDF is working fine, however there are cases within the document where I sometimes end up with the start of a paragraph at the end of the page, then the body of the paragraph on the next page. This means that the bold text serving as the title within the paragraph appears at the end of the page but the body appears on the next one.
I know I could add a page break prior to the start of the paragraph, but it's equally possible that it starts nearer the start of the page so doing this would also result in some cases in a broken layout.
Is it possible to determine the distance from the end of the page when adding a paragraph so that I can decide at that point whether a page break is needed?

Pages do not exist yet when you create a MigraDoc document, so you cannot determine on which page an item will be or where on a page.
You can set the property Format.KeepTogether of the Paragraph to true to prevent page breaks within the paragraph.
If the bold heading is a separate paragraph, then you can set the property Format.KeepWithNext of the Paragraph to true to prevent page breaks between this paragraph and the next one. This could be the better approach if the paragraph has a long body.

Related

MigraDoc page break on sub-sections

I am using MigraDoc which might generate a document like the following example:
However I want to be able to 'bind' a given number of paragraphs/tables (or anything else) together so that if a page break is detected anywhere during any of the items, the whole block is moved onto the next page - for example (where highlighted text is all 'bound' together somehow):
Hope the question makes sense...?! I’m not sure where to start with this but have a definitive requirement for it!
Paragraphs have a KeepTogether property that prevents pagebreaks within the paragraph.
Paragraphs have a KeepWithNext property that prevents pagebreaks between this paragraph and the next one. A typical use case are head lines that make no sense at the bottom of the page.
For tables, see here:
https://stackoverflow.com/a/1327228/162529

How to remove some data in Header in next page (RDLC Report)

I'm having a trouble on creating reports for my client because of the format. I just want to display the logo on the first page of my report and the rest will display without the logo. Please see my sample format.
Note: I dont want to remove the title on my header because I want to show that to all pages. I just want to remove or hide some data on header.
Using the following expression for the Hidden property should give you the desired behavior, like Ashnish Emmanuel suggested.
=(Globals!PageNumber <> 1)
When an item gets hidden, the objects below will move up. This means that the header's size should indeed shrink. This should then cause the body to move up as well.
The size of the body won't really change , there will just be more space on the page for the body to use.
However, if you defined a fixed height for the header, this will not force it to shrink because it will keep the empty space behind the last item. Which will mean that your body won't move up either. If you wish to create space between controls I suggest you always do it inside a report item (ex: rectangle, textbox, tablix) because this will give you more control over it (expressions).
Another solution is to remove the report header all together and work with a Tablix with a single column. You can replace the TextBoxes in the cells with Rectangles. The header row has the same functionalities as the page header, but you also have a CanGrowand CanShrink property which could solve your problem. You can also define multiple header rows which would allow you to hide an entire row with ease.
For the row used as body, you should then re-size the rectangle to be the same size as the actual page. And set the Keep Togetherproperty as true. This will then break the same way like the regular report body.
I think you are looking for Report Header.
In RDLC any control which is out the Table or the Tablix it will not be repeated, hence work as report header !
if you want to repeat , you place the item/data it in page header , use it for your Title.

Hide part of text temporarily, show after user clicks certain element

I'm making a detail page about certain items.
This detail page can contain large blocks of text, and the customer would like to only show the first 100 letters and then put a " ... more " at the end.
When the user clicks this " ... more " the rest of the text can be shown.
Biggest problem: the text is currently is a CMS and has large varieties. Some is pure text, some have html elements in them ...
I tried to cut off the text and put them in spans. Then i could show/hide these spans as i please. The issue here is that there can be a starting element of a certain tag in the first span and the closing element can be in the second span. This causes the DOM hierarchyto be faulty and the result is never pretty.
Does anyone know a ( other ) way to achieve this or a library i can use ?
To be able to extract "readable" characters you need to get the content into a plain text format (get rid of the mark-up).
Since the content is stored in a cms it is likely that the content is structured to be well formed - thus xhtml.
If that is the case you can treat the content as XML. Get the root node and get the innertext property there-of. Then you will have plain text - no tags - and can easily cut it after the first 100 characters or whatever the requirement is.
Hopefully the content doesn't contain js/css!
Edit:
It seems that the markup must be retained.
Try the following xsl to transform and truncate the content:
https://gist.github.com/allen/65817

Delete blank pages from WORD open XML

I have successfully generated a word document file using open XML, but I have got too many blank pages,
how can i remove them ?
This depends on how those blank pages are represented in the Open XML; you may want to post a sample document to demonstrate exactly how your blank pages are represented.
But let's take the case of a Word document in which a user has inserted extra page breaks (by hitting ctrl-enter in Word), resulting in blank pages. These page breaks will be represented in the XML as:
<w:br w:type="page"/>
The page will still have plenty of tags in it for spacing, fonts, etc.; and the page may display header and footers, too. But let's define a blank page as one which has no new paragraph text. In Open XML, new text is displayed with a w:t tag.
So, in order to remove blank pages created by extra page breaks with no text in between, we can run the following regular expression on the XML document, replacing with blank (""):
<w:br w:type="page"/>(.(?!<w:t>))*(?=<w:br w:type="page"/>)
This regex will search for a series of two or more page breaks with no new text in between, removing all but the last one.
(Note that this won't take care of blank pages at the end of the document, which is a bit trickier. Additionally, if you'd like to account for pages with images, textboxes, etc., the regex will have to be expanded to include the relevant items).

How to retrieve all the paragraph in the specified particullar page using C#(4.0) and Open Xml Sdk(2.0)?

We are developing C#.Net(4.0) Windows Form Based Application with the use of Open Xml Sdk(2.0) for manipulating MS-WORD Files.Now i want to get the all the paragraphs in particular page.The user prompted for getting particular page no of the word file to get the all the paragraphs inside the user selected page number. How i do it?
Taking a quick look at the underlying XML it doesn't look like there is an attribute on the paragraph element that will tell you which page it will appear on. The best suggestion I can give you is to have some placeholder text at the top and bottom of each page. Then search for the a certain instance of the placeholder text based on which page the user specifies. Once you have a starting point you could retrieve all paragraphs between the two placeholder paragraph elements.
For example, if a user enters in page two, you would search for the third instance of a paragraph that contains this placeholder text and then retrieve all paragraphs until you reach the next instance of the placeholder text. I know this isn't ideal, but its one workaround I could think of that might be feasible.

Categories

Resources