Free Support Forum - aspose.com

How to add revisions into Word document using Java

Hi
I am processing a Para Run by Run and detecting that isInsertRevision / isDeleteRevision which seems to be correct for the following text()
How do I access the information for this change please ?

Cheers
Jan

@JanUrbanski

You can use Revision.Author and Revision.DateTime properties to achieve you requirement. Please read the following article for more detail.
Manage Tracking Changes

Hi Tahir,
I eventually found that I can match a Run with a revision so was able to collect author and date for the specific run (insert or delete)
The piece I am missing is how to build a new word document and add insertions and deletes.
I see startTrackRevisions(author, date) starts a recording and for genuine inserts this is fine.
However I am building from an xml stream where I told what the revs are. So frozen - I need to add the text 'frozen ’ but as a delete by author , time. How would I approach this please.
Thanks
Jan

Sorry I pasted xml which has gone… Correction

However I am building from an xml stream where I told what the revs are. So I am told to insert the word 'frozen ’ but mark it as a deleyte by author , time. How would I approach this please.
Thanks
Jan

@JanUrbanski

Please note that Aspose.Words mimics the behavior of MS Word. When track changes of document is turned on and text is deleted from the document, MS Word makes the text as deleted revision.

Could you please share complete detail of your use case along with input and expected output documents? We will then provide you more information about your query.

Hi Tahir,
I am creating a new document using Docwriter class.
original_jan.zip (974 Bytes)
The attached is an xml file that is my input to form the Word file.
The element <revision…/> tells me whether its insert or delete, the author and the date.
I need to create the word file with normal word tracking show the inserts and deletes giving author/date as per normal word revisions. inserts underlined and deletes struck through.
How can I do this please?

Thanks
Jan

@JanUrbanski

Please note that Aspose.Words does not provide API to create XML tags as revisions. MS Word also does not create such tags.

Hi Tahir, I think showing the xml was my mistake. I have a java app that uses the Aspose Words API to build a Word document from the said xml. I do not expect the xml to drive a word document creation. The xml describes what the content should look like (in this case insert or delete).
Here follows a code snippet of what I am trying: -

this.ourDocumentWriterInterface.startTrackRevisions(author, date);
String type = ( aParaItem.getAttributes().getNamedItem(“type”) != null ) ? aParaItem.getAttributes().getNamedItem(“type”).getNodeValue() : “insert”;
if ( type.equals(“delete”)) { // the xml tells me what it is

				this.ourDocumentWriterInterface.getDocumentBuilder().startBookmark("ss");
				
				processNodes(aParaItem.getChildNodes(), paragraphFormat); // this essentially writes the content to docWriter
				
				this.ourDocumentWriterInterface.getDocumentBuilder().endBookmark("ss");

				this.ourDocumentWriterInterface.getDocumentBuilder().moveToBookmark("ss", true, false);
				this.ourDocumentWriterInterface.getDocumentBuilder().getCurrentNode().remove();
				this.ourDocumentWriterInterface.stopTrackRevisions();

			} else {
				processNodes(aParaItem.getChildNodes(), paragraphFormat);
				this.ourDocumentWriterInterface.stopTrackRevisions();
			}

The insert works well but deletion of the content added does not result is Word having struct out content.
I am using a bookmark but I also tried removing the Run but no delete in the resulting Word file

So is ‘startTrackRevisions’ this the only way to get word tracking ?
By inserting content and then deleting it seems cunky. Should it work as I cannot get it to show in Word.
Hopefully this clears up my bad steer on xml
Cheers
Jan

@JanUrbanski

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

cloneMe.zip (200.3 KB)
Hi
In putting a sample together I have actually figured out how delete tracking is created. But I still would ask if this is the correct way of creating revision tracking?
Inserting content then removing it seems a little cumbersome ?

Please let me know

thanks

Jan

@JanUrbanski

Yes, your code example and understanding is correct about adding delete revision.

Thanks for your help tahir
Cheers

Jan