none
How to rotate a picture being added to a word file RRS feed

  • Question

  • I am adding a picture from the disk to a word file. The picture apeared rotated.

    I rotated the source picture (on disk). It appears correctly when I open the file on the computer, yet when I rerun the C# VS 2017 program, it still appeared wrongly (not rotated) on the ms-word output file.

    Is there a way to add it rotated? change the rotation after the addition? 

    Here is the code I use:

               var image = doc.AddImage(Zeff_pic_file);
                var picture = image.CreatePicture(300, 150);
                var prgrph = doc.InsertParagraph("Zeff family");
                prgrph.AppendPicture(picture);
                doc.Save();

    • Moved by CoolDadTx Monday, March 18, 2019 1:54 PM Office related
    Saturday, March 16, 2019 5:50 PM

All replies

  • Hello, here is just an alternative solution based on Spire.Doc - a .NET Word Componenet. 

    using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    using System.Drawing;
    
    namespace RotateImage
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Create a Word document
                Document document = new Document();
                Section section = document.AddSection();
    
                //Add a paragraph
                Paragraph paragraph = section.AddParagraph();
    
                //Insert an image 
                DocPicture pic = paragraph.AppendPicture(Image.FromFile(@"C:\Users\Administrator\Desktop\2019-03-15-barocde.png"));
    
                //Rotate image
                pic.Rotation = 30;
    
                //Save to file
                document.SaveToFile("output.docx", FileFormat.Docx);
            }
        }
    }


    Monday, March 18, 2019 2:01 AM
  • Please specify the library you're using to create Word document when asking this type of question. By default this forum assumes OpenXML SDK because it's the library provided by Microsoft. You're strongly encouraged to ask question in the forum / support provided by your library's vendor if they provided it.

    Btw, no matter it's Spire.Doc as in the above reply or Xceed Documents Libraries the code appears to be the same - just set the .Rotation property of pic.



    • Edited by cheong00 Monday, March 18, 2019 4:18 AM
    Monday, March 18, 2019 4:15 AM
  • Please specify the library you're using to create Word document when asking this type of question. 

    Good point, I agree. In my case I used xceed, but I am not sure I made the right decision, to carry tasks like adding tables to a ms-word document and format it's cells. I would appreciate other suggestions. 
    Monday, March 18, 2019 6:03 AM