Hi, i m trying to append html to my word document through rest call. However it is giving error:{
“Error”: {
“Message”: “After parsing a value an unexpected character was encountered: m. Path ‘Text’, line 3, position 11.”
},
“RequestId”: “Root=1-620f7e4e-083df7480d879bb065c8939f”
}
Kindly see the attached file for complete requesttestFiles.zip (2.8 KB)
I am getting the following error when i make the request:
500 Internal Server Error: "{ “Error”: { “Message”: “Object reference not set to an instance of an object.” }
@AhmedTariq6
It looks like your HTML text issue. I have logged a ticket WORDSCLOUD-1931 in our issue tracking system for further investigation. We will keep you updated about the issue resolution progress within this forum thread.
Okay, thank you. Waiting for the response
@AhmedTariq6
We have investigated the issue and found the issue happens because of wrong HTML passing. When we read the HTML file to a string variable as follows, it insert HTML into Microsoft Word Doc in Java using Aspose.Words REST API without any issue.
Sample.docx (11.2 KB) Sample_output.docx (10.6 KB)
Steps to Insert HTML into Microsoft Word Doc in JAVA
- Free sign up with aspose.cloud to get the credentials
- Create an new Maven Project in Java IDE and add Aspose.Words Cloud SDK for Java Maven dependency
- Create an instance of Aspose.Words Cloud API
- Read the HTML file in a string
- Create ReplaceWithTextRequest to Insert HTML into the Word template from cloud storage with replaceWithText API method
- Run the code and that’s it
Add HTML File in Word Document JAVA
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.aspose.words.cloud.ApiClient;
import com.aspose.words.cloud.ApiException;
import com.aspose.words.cloud.api.WordsApi;
import com.aspose.words.cloud.model.DocumentResponse;
import com.aspose.words.cloud.model.ReplaceRange.TextTypeEnum;
import com.aspose.words.cloud.model.requests.ReplaceWithTextRequest;
public class ReplaceHTMLText {
public static void main(String[] args) throws IOException, ApiException {
// TODO Auto-generated method stub
// Get Client ID and Secret from https://dashboard.aspose.cloud/
// Create an instance of Aspose.Word Cloud
WordsApi wordsApi = new WordsApi("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx", "https://api.aspose.cloud");
ApiClient client = wordsApi.getApiClient();
client.setConnectTimeout(12 * 60 * 1000);
client.setReadTimeout(12 * 60 * 1000);
client.setWriteTimeout(12 * 60 * 1000);
String htmlData = new String(Files.readAllBytes(Paths.get("C:\\Temp\\intialTemplate.html")));
com.aspose.words.cloud.model.ReplaceRange requestRangeText = new com.aspose.words.cloud.model.ReplaceRange();
requestRangeText.setText(htmlData);
requestRangeText.setTextType(TextTypeEnum.HTML);
try {
ReplaceWithTextRequest request = new ReplaceWithTextRequest("Sample.docx", "id0.0.0", requestRangeText, null, null, null, null, null, null);
DocumentResponse result = wordsApi.replaceWithText(request);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
1 Like
Thank you so much for your response. That works perfectly fine
1 Like
The issues you have found earlier (filed as WORDSCLOUD-1931) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John