Add image in the page after a table

2 posts, 0 answers
  1. Mihajlo
    Mihajlo avatar
    47 posts
    Member since:
    Aug 2018

    Posted 03 Jun Link to this post

    I would like from code to insert a table in text, and then insert an image in the very first next page. So I insert a table, then insert a section break, a then insert an image. But it may happen that the table is already at the end of the page, and the section break would spill to the next page, which would result in the image being on the third page with the page in the middle being completely empty. Can I prevent this from happening? The user will be able to edit the text, add lines before the table, and so cause the empty page even if it wasn't there before my insert. The user will not be able to edit the table or anything else after it.
  2. Martin
    Admin
    Martin avatar
    93 posts

    Posted 08 Jun Link to this post

    Hi Mihajlo,

    You can achieve the desired functionality by creating a Section and insert the required elements as blocks in it. The only specific thing is to add a PageBreak inline before the image in the paragraph (instead of insert section break) where you are going to add this image. Check the following code snippet:  

    Paragraph paragraph = new Paragraph();
    
    ImageInline image;
    using (MemoryStream ms = new MemoryStream())
    {
    	Image.FromFile("Telerik_logo.png").Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    	image = new ImageInline(ms);
    }
    
    // Insert Page Break
    Break br = new Break(BreakType.PageBreak);
    paragraph.Inlines.Add(br);
    
    paragraph.Inlines.Add(image);
    section.Blocks.Add(paragraph);

    I am attaching a demo example demonstrating this functionality. Please, feel free to modify it in a way closer to your scenario.

    As a side note, if you decide to create each element in a separate section this will split them into different pages and you won't need to insert a page break.

    I hope this helps. Please, let me know if this is not your case or if there is anything else I can assist you with.

    Regards,
    Martin
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top