I was trying to access Pdf replace text using Javascript via C++ from Aspose.PDF, but i am not getting any output with replaced text.
The file i am uploading, the same file i am getting as output. The below code i am using given in the Aspose example.
Kindly let me know, if anything i am missing.
var ffileReplaceText = function (e) {
const file_reader = new FileReader();
file_reader.onload = (event) => {
/Replace text in a PDF-file and save the “ResultReplaceText.pdf”/
const json = AsposePdfReplaceText(event.target.result, e.target.files[0].name, “Aspose”, “ASPOSE”, “ResultReplaceText.pdf”);
if (json.errorCode == 0) document.getElementById(‘output’).textContent = json.fileNameResult;
else document.getElementById(‘output’).textContent = json.errorText;
/Make a link to download the result file/
DownloadFile(json.fileNameResult, “application/pdf”);
};
file_reader.readAsArrayBuffer(e.target.files[0]);
};
It seems you are trying to replace text in a PDF using JavaScript via C++ with Aspose.PDF, but the output PDF remains unchanged. Here are a few things to check and consider:
Ensure Proper Binding: Make sure that the PDF file is correctly bound before attempting to replace text. In the Java example, the bindPdf method is used to load the PDF file. Ensure that your JavaScript implementation is correctly reading the file and passing it to the Aspose function.
Check Text Replacement Logic: In the Java example, the replaceText method is called to replace specific text. Ensure that the text you are trying to replace (“Aspose”) actually exists in the PDF. If the text is not found, the output will remain unchanged.
Error Handling: Your code checks for an error code after attempting to replace the text. If the error code is not zero, it indicates an issue. Make sure to log or display the error message to understand what went wrong.
File Output: After the replacement, ensure that the output file is being saved correctly. The DownloadFile function should point to the correct path where the modified PDF is saved.
Here’s a simplified version of what your JavaScript function might look like, ensuring that you are binding the PDF and replacing text correctly:
Make sure to verify these points, and if the issue persists, consider checking the Aspose documentation or forums for additional troubleshooting steps.