none
Get WaterMark details using open XML RRS feed

  • Question

  • I am using open <g class="gr_ gr_13 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="13" id="13">xml</g> SDK to parsing word document. I am able to parse all types of data except WaterMark. Please help me to get WaterMark details from <g class="gr_ gr_193 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="193" id="193">word</g> document. 
    Friday, February 16, 2018 8:14 AM

Answers

  • Hello Venkatesan Ka,

    Please try to check if below code could work for you.

     string fullpath = @"C:\Users\v-guaxu\Desktop\Test.docx";
                using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fullpath, true))
                {
                    string headerRelationshipId;
                    string headerType = "";
                    Document mainDocument = wordDoc.MainDocumentPart.Document;
                    foreach (HeaderReference headerReference in
            mainDocument.Descendants<HeaderReference>())
                    {
                        headerRelationshipId = headerReference.Id.Value;
                        headerType = headerReference.Type.Value.ToString();
                        HeaderPart headerPart = (HeaderPart)(wordDoc.MainDocumentPart.GetPartById(headerRelationshipId));
                        if (headerType == "Default")
                        {
                            ImagePart imagePart= headerPart.ImageParts.First();
                            Stream stream = imagePart.GetStream();
                            long length = stream.Length;
                            byte[] byteStream = new byte[length];
                            stream.Read(byteStream, 0, (int)length);
    
                            FileStream fstream = new FileStream(@"C:\Users\v-guaxu\Desktop\Exported.jpg", FileMode.OpenOrCreate);
                            fstream.Write(byteStream, 0, (int)length);
                            fstream.Close();
                        }
                    }
                }

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Venkatesan Ka Saturday, February 24, 2018 1:54 AM
    Friday, February 23, 2018 3:50 AM

All replies

  • Hell Venkatesan Ka,

    What do you mean details?  Is the water mark a picture or do you want to get the string of the water mark?

    Besides, which development language do you use? C#? VB?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 19, 2018 12:01 PM
  • Hi Terry,

    Thanks for reply..

    I need to get Picture WaterMark from Docx using C#. Could you please help on this.

    Tuesday, February 20, 2018 8:03 AM
  • Hello Venkatesan Ka,

    Please try to check if below code could work for you.

     string fullpath = @"C:\Users\v-guaxu\Desktop\Test.docx";
                using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fullpath, true))
                {
                    string headerRelationshipId;
                    string headerType = "";
                    Document mainDocument = wordDoc.MainDocumentPart.Document;
                    foreach (HeaderReference headerReference in
            mainDocument.Descendants<HeaderReference>())
                    {
                        headerRelationshipId = headerReference.Id.Value;
                        headerType = headerReference.Type.Value.ToString();
                        HeaderPart headerPart = (HeaderPart)(wordDoc.MainDocumentPart.GetPartById(headerRelationshipId));
                        if (headerType == "Default")
                        {
                            ImagePart imagePart= headerPart.ImageParts.First();
                            Stream stream = imagePart.GetStream();
                            long length = stream.Length;
                            byte[] byteStream = new byte[length];
                            stream.Read(byteStream, 0, (int)length);
    
                            FileStream fstream = new FileStream(@"C:\Users\v-guaxu\Desktop\Exported.jpg", FileMode.OpenOrCreate);
                            fstream.Write(byteStream, 0, (int)length);
                            fstream.Close();
                        }
                    }
                }

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Venkatesan Ka Saturday, February 24, 2018 1:54 AM
    Friday, February 23, 2018 3:50 AM
  • Thanks Terry for helping. It is working. 
    Saturday, February 24, 2018 1:53 AM