Export DOCX to PDF with images

6 posts, 0 answers
  1. ghini
    ghini avatar
    28 posts
    Member since:
    Sep 2012

    Posted 17 Jan Link to this post

    Hello to all,
    I have a DOCX file with a header logo.
    I import the file in a RadFlowDocument and edit it with a RadFlowDocumentEditor.
    If I save it in a new DOCX everything it is OK.
    If I save a PDF (with Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider) the image disappears.

    The image in my DOCX is "in line".
    So I think I should not convert images to "ImageInline", right?
    If so, why have not the class Telerik.Windows.Documents.Model.ImageInline?
    My Telerik version is 2016.2.607.

    Thank you
  2. Tanya
    Admin
    Tanya avatar
    583 posts

    Posted 19 Jan Link to this post

    Hello,

    We are unaware of issues related to the export of inline images to PDF and I am not sure what might be causing the behavior you are experiencing. Is it possible to share a document showing the exact case so we can test it locally?

    Regards,
    Tanya
    Telerik by Progress

  3. Frankfrut RSC IM
    Frankfrut RSC IM avatar
    3 posts
    Member since:
    Oct 2012

    Posted 20 Jan Link to this post

    Hi Ghini,

    I have the same problem with 2016.2.607 when saving a RadFlowDocument as PDF.

    To solve this, I had to do first create a new image with the existing data and then resave it as a PNG:

    RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
    Paragraph imageParagraph = datacell5.Blocks.AddParagraph();
     
    //Create new image as the PDF export won't display
    System.Drawing.Image img =  System.Drawing.Image.FromStream(ms);
     
    //Must resave the byte[] from ms to ensure that it can be inserted into the PDF properly.
    using (var msImg = new MemoryStream())
    {
        img.Save(msImg, System.Drawing.Imaging.ImageFormat.Png);
        editor.MoveToParagraphStart(imageParagraph);
        int newHeight = (int)(img.Height / ((double)img.Width / 100));
        editor.InsertImageInline(msImg, "png", new Size(100, newHeight));
    }

     

    Once I did this step, the images were correctly added to the PDFs.

    Hope this helps!

  4. Frankfrut RSC IM
    Frankfrut RSC IM avatar
    3 posts
    Member since:
    Oct 2012

    Posted 20 Jan in reply to Frankfrut RSC IM Link to this post

        using (var ms = new MemoryStream(row["Picture"].ConvertOrDefault<byte[]>()))
        {
            RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
            Paragraph imageParagraph = datacell5.Blocks.AddParagraph();
             
            //Create new image as the PDF export won't display
            System.Drawing.Image img =  System.Drawing.Image.FromStream(ms);
             
            //Must resave the byte[] from ms to ensure that it can be inserted into the PDF properly.
            using (var msImg = new MemoryStream())
            {
                img.Save(msImg, System.Drawing.Imaging.ImageFormat.Png);
                editor.MoveToParagraphStart(imageParagraph);
                int newHeight = (int)(img.Height / ((double)img.Width / 100));
                editor.InsertImageInline(msImg, "png", new Size(100, newHeight));
            }
        }
    }

     

    Sorry, forgot the first line of code.
  5. Tanya
    Admin
    Tanya avatar
    583 posts

    Posted 25 Jan Link to this post

    Hi Frankfrut,

    As I mentioned in my previous post, the inline images are supported and I cannot say what the reason might be before testing a sample document.

    Since you haven't specified the type of the image you are having troubles with, I would like to mention that the floating images are not supported by PdfFormatProvider and are skipped when you export PDF documents. If you would like, you can vote for the implementation of that feature and track its status through the related public item.

    Regards,
    Tanya
    Telerik by Progress

  6. ghini
    ghini avatar
    28 posts
    Member since:
    Sep 2012

    Posted 14 Feb in reply to Tanya Link to this post

    Hi Frankfrut, thanks for your help!
    I'm sorry but I do not understand the first line ... What is row["Picture"]?

    However I solved by modifying the original document and using PNG images.
    Now the output in DOCX is changed but well or other problem in the PDF generation. All paragraphs of justified text in DOCX, are left-aligned in the PDF.

    thank you so much
Back to Top