Read a docx file in Office Open XML (OOXML)

Hi
How to read a docx file in Office Open XML (OOXML) format(without images). And then manipulate data Insert element before/after an element), then write the docx file. If you can just give me an example for this it will be really helpful to me…

Hi Rinku,

Thanks for your inquiry.

You can load DOCX file into Aspose.Words Document instance and then remove all images inside that document by using the following code snippet:

Document doc = new Document(@"C:\test\in.docx");

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape,
true, false);
foreach (Shape shape in
shapes)
{
    if
    (shape.HasImage)
    {
        shape.Remove();
    }
}

Also, please visit the following link to learn how to extract images from a Document by visiting the following link:
https://docs.aspose.com/words/net/working-with-images/

Once the document is loaded and all images are removed/extracted, you would be able to easily insert elements after reading the article suggested below:
https://docs.aspose.com/words/net/programming-with-documents/

Finally, I would suggest you to please read the following API page for a variety of saving options:
https://reference.aspose.com/words/net/aspose.words/document/save/

Please let us know if you need more information, We are always glad to help you.

Best Regards,

But I need to read the docx without any images from the beginning. So that I will not store any images in memory(Sometimes user can upload big size images in template)… Is this possible with aspose???

Hello
Thanks for your request. I’m afraid there is no way to achieve what you need using Aspose.Words, without loading the document to Aspose.Words Document Object Model.
Best regards,

Hi there,

Thanks for your inquiry.

We have an interface where you can choose to load or skip images during document open: https://reference.aspose.com/words/net/aspose.words.loading/iresourceloadingcallback/.

However I’m afraid this only takes effect when HTML based formats are loaded, and not OOXML documents. We will look into extending this behavior for all load formats so you can skip loading images. I have linked your request to the appropriate issue. We will inform you as soon as there are any developments.

I’m afraid in the mean time you will need to use the work around described by Awais.

Thanks,

Hi
Thanx for your quick replies. So if I remove images after loading ,whether I have to load all the images back while saving the document after processing or Aspose will take care of that???

Hello
Thanks for your inquiry. If you remove all images from the document, they will be lost.
Please see the following link to learn more about Aspose.Words features:
https://docs.aspose.com/words/net/product-overview/
Best regards,

Hi
What ever links and example you are giving are in .net. If you can give some java examples it will be a great help. Because I am working on Aspose.words java.

Thank You

Hello Rinku,
Thanks for your inquiry. The same for Java
You can load DOCX file into Aspose.Words Document instance and then remove all images inside that document by using the following code snippet:

Document doc = new Document("C:\\test\\in.docx");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true, false);
for (int i = 0; i < shapes.getCount(); i++)
{
    Shape shape = (Shape)shapes.get(i);
    if (shape.hasImage())
    {
        shape.remove();
    }
}

Also, please visit the following link to learn how to extract images from a Document by visiting the following link:
http://www.aspose.com/documentation/java-components/aspose.words-for-java/howto-extract-images-from-a-document.html
Once the document is loaded and all images are removed/extracted, you would be able to easily insert elements after reading the article suggested below:
http://www.aspose.com/documentation/java-components/aspose.words-for-java/inserting-document-elements.html
Finally, I would suggest you to please read the following API page for a variety of saving options:
https://reference.aspose.com/words/net/aspose.words.saving/saveoptions/
Please let us know if you need more information, We are always glad to help you.
Best Regards,

The issues you have found earlier (filed as WORDSNET-5600) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(51)