Hello Nicklas,
After loading the document, you can enumerate the ImageInline elements and scale them according to the actual page size:
private
void
ScaleImages()
{
IEnumerable<ImageInline> images =
this
.radRichTextEditor1.Document.EnumerateChildrenOfType<ImageInline>();
foreach
(ImageInline image
in
images)
{
Telerik.WinControls.RichTextEditor.UI.Size size =
this
.GetScaledSize(image.Width, image.Height);
image.Size = size;
}
}
private
Telerik.WinControls.RichTextEditor.UI.Size GetScaledSize(
double
originalPixelWidth,
double
originalPixelHeight)
{
Telerik.WinForms.Documents.Layout.Padding sectionmargin =
this
.radRichTextEditor1.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection.ActualPageMargin;
if
(originalPixelWidth == 0 || originalPixelHeight == 0)
{
originalPixelWidth = 10;
originalPixelHeight = 10;
}
double
width = originalPixelWidth;
double
height = originalPixelHeight;
Section currentSection =
this
.radRichTextEditor1.Document.CaretPosition.GetCurrentSectionBox().AssociatedSection;
Telerik.WinForms.Documents.Model.SizeF pageSize = (Telerik.WinForms.Documents.Model.SizeF)currentSection.GetType()
.GetProperty(
"ActualPageSize"
, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(currentSection);
double
maxWidth = pageSize.Width - (sectionmargin.Left + sectionmargin.Right);
double
maxHeight = pageSize.Height - (sectionmargin.Top + sectionmargin.Bottom);
width = Math.Min(maxWidth, width);
height = Math.Min(maxHeight, height);
double
ratio = originalPixelWidth / originalPixelHeight;
width = Math.Min(width, height * ratio);
height = width / ratio;
return
new
Telerik.WinControls.RichTextEditor.UI.Size(width, height);
}
I hope this will help.
Regards,
Hristo
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.