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();
}
}