Feb 01, 2010 Deleting a phantom image in Microsoft Word. By default, the command is located at the far right of the Home tab. Click the Select button to find a dropdown list, and then click Select Objects. After doing this, I was able to click directly on the image (which somehow had been embedded as an object instead of a picture) and then tap the Delete button on my keyboard.
Active2 years, 4 months ago
I am trying to delete all embedded object from Word and PowerPoint files using openxml SDK. I am new to Open XML and not sure whether I am doing this correctly. Below is the code I have. My intention is to remove any objects embedded and to delete images embedded. Both codes when executed are giving errors.
Code that I tried to delete all embedded items in the document.
Code that I tried to delete all images in the document. (This works partially if I don't have any objects embedded in the document.)
When I run the above code the file I use is getting corrupted. I would like to know how to remove all embedded objects from Word without corrupting the file.
I haven't done anything on PowerPoint yet, but I hope it would be similar to Word document.
Kannan SureshKannan Suresh4,03133 gold badges2828 silver badges5656 bronze badges
2 Answers
I managed to find a solution for my problem. I had to dive in to the concepts of Open XML SDK to get this. However, I am not so sure on whether this is the optimal solution.
Goal
- Remove all embedded objects in PowerPoint and Word.
- Remove all images in PowerPoint and Word.
For Word
For PowerPoint
Kannan SureshKannan Suresh4,03133 gold badges2828 silver badges5656 bronze badges
In my experience, the fastest way to 'corrupt' an OpenXML document is to have a bad relation pointer. The fastest way to get a handle of what's behind those cryptic error messages is to go straight to the raw OpenXML markup.
To get an idea of what is happening:
- Make a copy of your file before running your code, call this
A.docx
- Run your code and make a copy of your result, call this
B.docx
- Rename
A.docx
andB.docx
toA.zip
andB.zip
Investigate the source file
First, inside of
A.zip
, open the file called [Content_Types].xml
. Take note of the parts that you would like to remove. Think of this file as a declaration to the word processor of the types of files that it will encounter in the sub-directories. Parts such as the document content (
word/document.xml
) or the footnotes part (word/footnotes.xml
) have their own relations parts named as [part path here].rels
. For example,
document.xml.rels
will hold relation information for things like charts, hyperlinks, and images in document.xml
; likewise, footnotes.xml.rels
holds information on things like hyperlinks in footnotes.xml
.Investigate the result file
Now open
B.zip
and compare the [Content_Types].xml
files. Do you see a part there that you intended to delete? Is there a part missing that you did not intend to delete?Inside of the
word
sub-directory in B.zip
, do you see any embedded files that are not listed in the [Content_Types].xml
file?If you take a look at the raw markup, and the error doesn't jump out at you, feel free to comment with what some more details about your file structure and we can troubleshoot from there.
Austin DrenskiAustin Drenski