Unplanned
Last Updated: 31 Oct 2018 08:11 by ADMIN
ADMIN
Svetoslav
Created on: 08 Jun 2015 15:02
Category: RichTextBox
Type: Bug Report
0
RichTextBox: NullReferenceException when printing document containing images in not supported formats or with empty source


The exception can be observed when printing document containing images with unsupported formats, or images with empty source (RawData = "").

The exception is with the following call stack:

   at Telerik.Windows.Documents.UI.HeaderFooterContainer.UpdateUI(SectionLayoutBox sectionBox, Boolean delayed)
   at Telerik.Windows.Documents.UI.HeaderFooterContainer.UpdateUI(SectionLayoutBox sectionBox)
   at Telerik.Windows.Documents.UI.DocumentPrintPresenter.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)


Workarounds:

If you click on print preview and print the document from the preview it is working;
     2. Use the following code

        this.radRichTextBox .PrintStarted += Rtb_PrintStarted;

        private void Rtb_PrintStarted(object sender, EventArgs e)
        {
            RadRichTextBox rtb = (RadRichTextBox)sender;
            foreach (var floatingImage in rtb.Document.EnumerateChildrenOfType<FloatingImageBlock>()
                                                      .Where(fi => !this.IsSupportedImageFormat(fi.ImageInline.Extension))
                                                      .ToList())
            {
                floatingImage.Parent.Children.Remove(floatingImage);
            }

            foreach (var inlineImage in rtb.Document.EnumerateChildrenOfType<ImageInline>()
                                                    .Where(i => !this.IsSupportedImageFormat(i.Extension))
                                                    .ToList())
            {
                inlineImage.Parent.Children.Remove(inlineImage);
            }
        }

        private bool IsSupportedImageFormat(string format)
        {
            return (format == "jpg") ||
                   (format == "jpeg") ||
                   (format == "png") ||
                   (format == "bmp");
        }   

0 comments