none
EnhMetaFileBits page selection issues RRS feed

  • Question

  • Hello Everyone,

    I have created a method which converts the selected word tables to images. For image conversion, I am using EnhMetaFileBits on the selected range of the Tables. Now the issue occurs, when my table splits into few more pages. However, this method only converts those sections, which fits for a single page, but if the table is 3 to 5 pages long, then it converts only the first page of the table.

    Here is the method:

    byte[] emfData = (byte[])wdApplication.Selection.EnhMetaFileBits;

    Let me know, how to get bytes from the next pages as well.

    Thanks,


    Shahab Abbasi

    Thursday, June 1, 2017 8:42 AM

Answers

  • Hi Shahab,

    I made a test with your code, and I could reproduce your issue.

    I made a test manually to select the entire table, Copy, then paste special as Picture, and I found, it could only paste the first page. It seems to be a limitation for Word.

    For a workaround, I would suggest you Copy and Paste the Table to Excel, then Copy and Paste the Table in Excel by Paste as Image, and then saved the Image. You could automation this option by code.

    If you have any issue with above steps, please feel free to let me know.

    Best Regards,

    Edward 


    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.

    Friday, June 23, 2017 6:53 AM

All replies

  • Hi Shahab Uddin Abbasi,

    you had just try to post a one line of code.

    with that one line I can only get information regarding that method.

    it is only use to represents a picture representation of how a selection or range of text appears.

    but it is not clear that how much area of table you had selected

    how you selected table ? in code or by user interface.

    if possible then try to post a code so that we can try to test your code on our side.

    try to select the whole table by its index number like mentioned below.

            wd.Table tbl = wdApp.Selection.Tables[1];

    Reference:

    Selection.EnhMetaFileBits Property (Word)

    Regards

    Deepak


    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.

    Friday, June 2, 2017 5:30 AM
    Moderator
  • Thanks for the reply Deepak,

    Here is the code, I used:

    int counter = 1;
                foreach (Word.Table wdTable in wdApplication.ActiveDocument.Tables)
                {
                    byte[] emfData = (byte[])wdTable.Range.EnhMetaFileBits;
                    if (emfData != null)
                    {
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(emfData);
                        Image temp = Image.FromStream(ms);
                        temp.Save("C:\\MyTable" + counter.ToString() + ".png", ImageFormat.Png);
                    }
                    counter = counter + 1;
                }

    If your table is 3-4 pages long, it shows only that content which fits to a single page.

    Thanks,


    Shahab Abbasi

    Friday, June 2, 2017 5:36 AM
  • Hi Shahab Uddin Abbasi,

    I am able to reproduce the issue on my side.

    I try to make a several test to solve the issue but unfortunately none of the solution work to save full table.

    I will try to search further and if I find any solution, I will try to provide you.

    Regards

    Deepak


    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.

    Friday, June 2, 2017 8:58 AM
    Moderator
  • Hi Shahab,

    I made a test with your code, and I could reproduce your issue.

    I made a test manually to select the entire table, Copy, then paste special as Picture, and I found, it could only paste the first page. It seems to be a limitation for Word.

    For a workaround, I would suggest you Copy and Paste the Table to Excel, then Copy and Paste the Table in Excel by Paste as Image, and then saved the Image. You could automation this option by code.

    If you have any issue with above steps, please feel free to let me know.

    Best Regards,

    Edward 


    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.

    Friday, June 23, 2017 6:53 AM