HI,
Thanks Jici I have updated my javascript which is as follows: -
try {
// Fetch the content inside the Rich Text Input (without toolbar)
var richText = document.querySelector(“#RTFF .ql-editor”).innerHTML; // Get inner HTML content
// Replace HTML tags with RTF syntax
var rtfContent = richText
.replace(/<p>/g, "\\par ") // Convert <p> to new paragraph
.replace(/<\/p>/g, "") // Remove closing </p>
.replace(/<br>/g, "\\line ") // Convert line break to RTF line
.replace(/<strong[^>]*>/g, "\\b\\cf1 ") // Convert <strong> to bold and blue in RTF
.replace(/<\/strong>/g, "\\b0\\cf0 ") // Close bold and color
.replace(/<em[^>]*>/g, "\\i ") // Convert <em> to italics in RTF
.replace(/<\/em>/g, "\\i0 ") // Close italics
.replace(/<a href="([^"]+)"[^>]*>([^<]+)<\/a>/g, "{\\field{\\*\\fldinst{HYPERLINK \"$1\"}}{\\fldrslt{\\cf1\\ul $2}}}") // Convert <a> to blue hyperlink with underline in RTF
.replace(/<[^>]+>/g, ""); // Remove any other remaining HTML tags
// Define the RTF header with the color table for blue text
var fullRtfContent = "{\\rtf1\\ansi\\deff0 {\\colortbl;\\red0\\green0\\blue255;} " + rtfContent + "}";
// Create a Blob from the RTF content
var blob = new Blob([fullRtfContent], { type: "application/rtf" });
// Convert Blob to base64
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function () {
var base64data = reader.result.split(",")[1]; // Get base64 data without the metadata
// Prepare the API request to upload the file
var fileName = "document.rtf";
fetch("https://inconversationskz.com/version-test/api/1.1/wf/upload_file", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"file_base64": base64data, // Send base64-encoded file
"file_name": fileName // Send file name
})
})
.then(response => response.json())
.then(data => {
console.log("File uploaded successfully:", data);
// Handle success (e.g., show a success message, update the UI, etc.)
})
.catch(error => {
console.error("Error uploading file:", error); // Error handling
});
};
} catch (error) {
console.error("Error generating RTF file: ", error); // Error handling
}
Now after this what should I do.
Thanks
Vijay