0

I have a MigraDoc pdf I am generating and have had the requirement to have some 'inline' tables, I needed to get two tables on a line so after investigating this I found TextFrames worked perfectly... Until it encounters the end of the page. Turns out TextFrames do not recognize the end of the page:

enter image description here (TextFrame are the red boxes)

So, I was wondering if anyone else had come up with a work around for this?

I had thought if I could find the position of the 'current location' I could calculate if the text frame is going to be too tall then manually inject a page break - but I can not seem to find the 'current position' - probably because it doesn't exist until post render??

Is there any way of getting the rendered height position of the 'current line' when coding or is there a better/easier way of doing what I am looking for?

CJH
  • 1,266
  • 2
  • 27
  • 61

2 Answers2

1

I have found a piece of code that returns the current position using a kind of pre-render:

    public double GetMigraHeightPosition()
    {
        MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(this.document);
        docRenderer.PrepareDocument();

        RenderInfo[] RenderInfos = docRenderer.GetRenderInfoFromPage(docRenderer.FormattedDocument.PageCount);
        RenderInfo r = RenderInfos[RenderInfos.Count() - 1];
        return r.LayoutInfo.ContentArea.Y + r.LayoutInfo.ContentArea.Height;
    }

So I am using this plus the height of the table to check if that is greater than the active page size (pagesize minus margins & header/footers). Seems to do the trick with regards to stopping the tables spilling into the footer... I still seem to be having the problem with the second table in the first row going onto the next page...?? Havent got a clue what is happening there?!

CJH
  • 1,266
  • 2
  • 27
  • 61
0

Object positions are determined when a document is being "prepared" before it is being rendered. If you make changes at that stage, you have to prepare the document again.

You can create tables with "invisible" cells. You can create tables within tables, but inner tables will not have pagebreaks within, so make sure each nested table fits on a single page.
See also:
https://stackoverflow.com/a/36304148/162529

  • Thanks for that - I had already encountered problems with tables within tables and page breaks... Which is the reason I ended up with TextFrames. – CJH May 02 '19 at 13:03
  • I have since however found a piece of code that will do a pre-render and return the current Y position which seems to work really effectively! Will update this page shortly! – CJH May 02 '19 at 13:04
  • I still have an issue where the second table of the first row is pushed onto the next page but have no idea why? I was going to put a new question specific to that with code snippets if you don't mind taking a look? ;) – CJH May 02 '19 at 13:14
  • I have asked the updated question here... https://stackoverflow.com/questions/55953600/migradoc-textframe-wrapstyle-on-page-break I hoped the fix I put in place would have addressed this but has not :( – CJH May 02 '19 at 13:30