This is a migrated thread and some comments may be shown as answers.

Add image in the page after a table

1 Answer 55 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Mihajlo
Top achievements
Rank 1
Mihajlo asked on 03 Jun 2020, 12:54 PM
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.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 08 Jun 2020, 11:25 AM

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.
Tags
RichTextEditor
Asked by
Mihajlo
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or