We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

noProof Attribute Applied to Merge Fields during Mail Merge to Turn Off Proofing in a Word 2016 RTF (NoProofing) Java Code

I’m having an issue with Aspose Word turning off Proofing functionality after I use its Mail Merge feature, for the values that are inserted into the document. Aspose was never asked to turn proofing off and the initial document has it turned on by default.

Looping through the document to turn proofing back on does not appear to fix the problem in the final document. After I’m done, it still comes out with proofing off. In fact, by looping through the whole document and setting setNoProofing() to any value, whether true or false, it will turn off proofing for every part of the document. Whereas, if I don’t loop and set that value, only the merge field will have proofing turned off. Either way it is a no win situation for our customers.

ProofingSample.zip (38.5 KB)

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.words.Document;
import com.aspose.words.MailMergeCleanupOptions;
import com.aspose.words.NodeCollection;
import com.aspose.words.NodeType;
import com.aspose.words.Run;
import com.aspose.words.SaveFormat;

public class GenerateDocument {

	public static String RequestText = "RequestText";
	  
	public static void main(String[] args) throws Exception {

		GenerateDocument genDoc = new GenerateDocument();

		InputStream in = genDoc.getClass().getClassLoader().getResourceAsStream("resources/SampleDoc.rtf");
		Document doc = new Document(in);
		
	    doc.getMailMerge().execute(new String[] {RequestText}, new Object[] {"new text and badtects"});

	    doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);
	    
	    NodeCollection<Run> collection = doc.getChildNodes(NodeType.RUN, true);
	    
	    for (Run run : collection) {
	    	
			run.getFont().setNoProofing(false);
		}	    
	    
	    ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
	    doc.save(dstStream, SaveFormat.RTF);
	    
	    byte[] buffer = (byte[]) dstStream.toByteArray();
	    
	    File file = new File("src/resources/outputfile.rtf");
	    
	    file.createNewFile();
	    
	    FileOutputStream fos = new FileOutputStream(file);
	    
	    fos.write(buffer);
	    
	    fos.close();
		
	}
}

@ldcDevelopment,

We have performed manual mail merge on your ‘input.rtf’ by using MS Word 2019 and observed that the behavior of MS Word 2019 is same as that of Aspose.Words’. Please check the following MS Word 2019 generated RTF file:

So, this does not seem to be a bug in Aspose.Words for Java API. Aspose.Words applies noProof attribute for mergefield field result during mail merge like MS Word does.

Secondly, we managed to reproduce this issue on our end when running the following simple code:

Document doc = new Document("E:\\Temp\\ProofingSample\\input.rtf");

for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)) {
    run.getFont().setNoProofing(false); // any value true/false will turn off proofing
}

doc.save("E:\\Temp\\ProofingSample\\awjava-20.1.rtf");

The ID of this issue is WORDSNET-19905. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-19905) have been fixed in this Aspose.Words for .NET 20.3 update and this Aspose.Words for Java 20.3 update.