I want to extract text from .doc file with table layout preserved and save the extracted text to a string.
Document document = new Document(inputStream);
TxtSaveOptions saveOptions = new TxtSaveOptions();
saveOptions.setPreserveTableLayout(true);
saveOptions.setSaveFormat(SaveFormat.TEXT);
document.save(txtFile, saveOptions);
For the above code, the extracted text is being saved to a file. Is there any way to save the extracted text directly to a string?
@Sathiya22
Please use Node.ToString method (SaveOptions) as shown below to get the desired output.
Document document = new Document(MyDir + "input.docx");
TxtSaveOptions saveOptions = new TxtSaveOptions();
saveOptions.setPreserveTableLayout(true);
saveOptions.setSaveFormat(SaveFormat.TEXT);
System.out.println(document.toString(saveOptions));
When saving the extracted text to string, I get java.lang.NoClassDefFoundError: com/aspose/words/SaveOptions error.
@Sathiya22
Perhaps, you are using the old version of Aspose.Words for Java. Please use the latest version of Aspose.Words for Java 20.12 to avoid this issue.
The same error occurs even when aspose.words 20.12 is used. Is there any other cause for this error?
@Sathiya22
The NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class and no definition of the class could be found.
Could you please ZIP and attach your input Word document here for testing? Please also share your working environment. We will investigate the issue and provide you more information on it.
I am using eclipse IDE to run the code. Is there any other possibility to save the extracted text directly to a string?
file-sample_500kB (1).docx.zip (538.4 KB)
I have uploaded a sample docx file.
@Sathiya22
We have tested the scenario using Eclipse and have not found the shared issue. Please make sure that you have installed the Aspose.Words for Java 20.12 correctly. Please check the attached image for detail. Eclipse Test.png (63.2 KB)
1 Like
Thank you very much for your support.