RadDocument - add ImageInline bitmap at 100% scaling in a table cell

4 posts, 1 answers
  1. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 17 Jul 2014 Link to this post

    How do you set the size of an inline image added to Word docx document using RadDocument?
    We need to add the image to a table and have the image scaled at 100%.  It scales the image at 156% when exporting to Word docx format
    Images added outside of a table are sized at 100% and not scaled up.

    When we use the following code to add an image outside of a table,.

    //Setup RadDocument
    RadDocument document = new RadDocument() { LayoutMode = DocumentLayoutMode.Paged };
    document.SectionDefaultPageSize = PaperTypeConverter.ToSize(PaperTypes.Letter);
    document.SectionDefaultPageOrientation = PageOrientation.Portrait;

    const double pageMarginSizeInches = 0.5;
    int marginSizeDip = (int) Unit.InchToDip(pageMarginSizeInches);
    document.SectionDefaultPageMargin = new Padding(marginSizeDip);

    //Add text and other document content


    //add more text and document content//output to .docx file

    //write to .docx file
    using (Stream outStream = new FileStream("out.doc, FileMode.Create))
      DocxFormatProvider provider = new DocxFormatProvider();
      provider.Export(document, outStream);

    //end of program

    void AddImageTable(RadDocument document)
    Section section = new Section();

    System.Drawing.Bitmap testImage = ( a 500 pixel by 500 pixel bitmap image taken of an application window)

    Table table = new Table();
    table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName;
    row = new TableRow();
    TableCell cell = new TableCell() { PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 20.0f)  };

    Paragraph par = new Paragraph();
    par.Inlines.Add(new Span("Image test"))


    cell = new TableCell() { PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 80.0f) };
    cell.Blocks.Add(AddImage(null, testImage, 0.0f));



    static Paragraph AddImage(string imagePath, System.Drawing.Bitmap bitmapImage)
    {   //add image from the assembly resource or from a Bitmap
      ImageInline imageTmp;
      Stream inStream;
      if (String.IsNullOrWhiteSpace(imagePath) == false)
       inStream = Application.GetResourceStream(new Uri(imagePath, UriKind.RelativeOrAbsolute)).Stream;
       imageTmp = new ImageInline(inStream);
       inStream = new MemoryStream();
       bitmapImage.Save(inStream, ImageFormat.Png);
       imageTmp = new ImageInline(inStream, new Size(bitmapImage.Width, bitmapImage.Height), "png");

    Paragraph par = new Paragraph();
    inStream = null;
     return (par);
     catch (Exception ex)
      System.Diagnostics.Debug.WriteLine("AddInlinePicture() - exception - " + ex.ToString() + "\n\n");

  2. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 17 Jul 2014 Link to this post

    The System.Drawing.Bitmap has
     height 500,
     width 500,
     horizontal resolution 149.987
     vertical resolution 149.987
     pixel format Format32bppArgb
     physical dimension width 500, height 500

  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Petya avatar
    973 posts

    Posted 22 Jul 2014 Link to this post


    Please find attached a sample application that uses the code you sent us with some minor changes to make it run. As far as I tested this, both when showing the document in RadRichTextBox and exporting it the image is with its original dimensions. Please let me know if I am missing something in your scenario.

    Looking forward to your reply.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  5. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 01 Oct 2014 in reply to Petya Link to this post

    We ended up going with fixed width tables and table cells since the percentage scaling did not work out.

Back to Top