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
Related
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.
Is there any way I can compare a word document(.docx) with a document template(.dotx) generated in microsoft word.
I want to do this comparison programmatically using c#.
I want to compare both documents word to word so that I can determine to which template the document belongs. I don't just want to compare the size of both but I want to compare the contents also.
By this comparison I want get the following results.
From which document template the document is generated.
In the document template, I want to check that at which place a particular information is stored.
Say for example I want to search for the communication information of a person, then I want to traverse the document and check that At which position the template has the area/section for Address.(i.e. Top left corner, top center, In a paragraph, In body etc)
In same way I want to extract other information too, Like Link to other documents etc.
After getting those positions I want to get that Information from the .Docx file.
Say, If I found that the Address in the top-left and there are five links referring to other documents in five different paragraphs. Then what I want is to get the Address and save it to a variable. After that I want to replace those link contents from placeholders to Actual hyperLinks. i.e If a Link is referring to Doc-A then Instead of just showing a Plain text I want replace it with A hyperlink to Doc-A.
Any suggestions?
Thank You.
Your question is rather too vague and involved to give a really good answer, however...
To find out from which template a document was generated the object model provides the property: Document.AttachedTemplate with will return the full file name. This is certainly better than comparing word-by-word (which is also very time-consuming)
The Word object model also provides the method CompareDocuments (belongs to the Word.Application class). This will "highlight" differences in the text content of two documents.
Links will be found in the Document.Hyperlinks collection
Getting the position of things is a bit chancy with Word and it depends on what you really mean by "top-left", etc. Better would be to construct the templates using content controls, form fields and/or bookmarks so that you can uniquely identify important sections. However, Word does provide the Range.get_Information method that can return relative and absolute positions on the page if that's what you really want.
I've written an extension to comb through code files line by line to detect certain patterns. The problem I'm seeing is that lines within collapsed sections are skipped when using TextSelection.LineDown() or similar.
I'm aware that TextSelection.OutlineSection() exists to create such sections, but is there a way to detect, and possibly expand or collapse them?
In your scenario you don't have to use TextSelection, since that is related to...text selection. To traverse the lines of a code file, given an EnvDTE.TextDocument, you have the TextDocument.StartPoint property to get a EnvDTE.TextPoint and then you create an EnvDTE.EditPoint with TextPoint.CreateEditPoint(). With an EnvDTE.EditPoint you can GetText(...), MoveToXXX(...) etc. EditPoints are not affected by collapsed text.
I want to know, how can I do make a page break in PDFPTable but I don't want it cut the table just after the table header ?
And I want to define a size to the body of my page but I don't know how can I make that can you help me please ?
According to this, no, you cannot manually force a page break within a table. Your primary alternatives are to either just make multiple tables or use WriteSelectedRows. If you are forcing a page break then you generally "know when" you want to do it so either option should work. Multiple tables allow you to still leverage iTextSharp's flow logic whereas WriteSelectedRows gives you more control but assumes you have calculated if things actually fit. See this for a sample of using WriteSelectedRows.
To control the document's size you can either use the constructor to Document which optionally takes a Rectangle and a margin or you can call SetPageSize on the Document if you want to control it per-page.
I'm generating an MS Word document from user data. The data is placed in a container which is serialized to XML, and the resulting XML is converted to OpenXML using XSLT. There are a few minor changes done programmatically in C# to generate the Word document, as they can't be done with XSLT.
There is a user requirement that an item be placed completely on one page without any associated data being split onto another page. Sometimes one item will fill up an entire page, and sometimes I can fit three or four items on one page (I need to insert a separator (horizontal rule) between items that fit on the same page.)
Is there a way to determine whether or not one item or OpenXML paragraph will fit entirely on the "current" page? This can be either via C# or XSLT, and I can work something out.
Unfortunately, the only way this can be reliably done is to actually render the output, including all of the font sizes, bolding, kerning and all that. Which means you have to do the pagination in Word, and then save it back to the OpenXML.