- Home
- Forum
- JavaScript - EJ 2
- Enable Paste from Buttons when enableLocalPaste is false
Enable Paste from Buttons when enableLocalPaste is false
I need to enable pasting from the system clipboard. The editor works correctly when I use Ctrl V but the paste buttons should be working properly.
As of April 2018, Chrome has added a permission for access to the user's system clipboard that looks like this:
The code to ask for permission and paste is very simple:
Can we please implement this permission popup to get the paste working?
Thank you
Hi Robert,
Currently, the document editor doesn’t provide support for pasting content from the context menu.
We have already logged this as feature request. We don’t have any immediate plans to implement this feature now.
We usually have an interval of at least three months between the releases. At the planning stage for every release cycle, we review all open features once again and finalize features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented.
You can track the status of feature from the below link:
Support for pasting content from the context menu in Document Editor in JavaScript | Feedback Portal
Regards,
Dhanush S
Hello,
Would it be possible for me to implement this myself? Can I extend the right click menu somehow?
Thank you,
Robert
Hi Robert,
Currently, we are checking the possibilities to achieve your requirement and will update the details on May 5, 2025.
Regards,
Dhanush S
Hi Robert,
Currently, we are checking the possibilities to achieve your requirement and will update the details on May 5, 2025.
Regards,
Dhanush S
Hi Robert,
We can paste the clipboard content on button click by following below steps
- You can copy the Html/text content
- Get the clipboard content on button click
- If you are copying HTML content, You can convert the Html to Sfdt using SystemClipboard API and paste the Sfdt string in Document editor.
- If you are copying Text content, you can insert using insertText API.
document.getElementById("paste").onclick = function () { getClipboardText(); }; async function getClipboardText() { try { const items = await navigator.clipboard.read(); for (const item of items) { if (item.types.includes("text/html")) { const blob = await item.getType("text/html"); const html = await blob.text(); getSfdt(html); return; } else if (item.types.includes("text/plain")) { const blob = await item.getType("text/plain"); const text = await blob.text(); container.documentEditor.editor.insertText(text); return; } } console.log(text); } catch (err) { console.error("Failed to read clipboard: ", err); alert("Clipboard access denied or not supported."); } } function getSfdt(html) { let http = new XMLHttpRequest(); http.open("POST", container.serviceUrl + "SystemClipboard"); http.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); http.responseType = "text"; //Serialize document content as SFDT. let sfdt = { content: html, type: ".html", }; // Handle the server response http.onreadystatechange = function () { if (http.readyState === XMLHttpRequest.DONE && http.status === 200) { let rtfContent = http.responseText; // Proceed to save the RTF content as a file console.log(http.response); container.documentEditor.editor.paste(http.response); } }; //Send the sfdt content to server side. http.send(JSON.stringify(sfdt)); } |
Server:
[AcceptVerbs("Post")] [HttpPost] [EnableCors("AllowAllOrigins")] [Route("SystemClipboard")] public string SystemClipboard([FromBody] CustomParameter param) { if (param.content != null && param.content != "") { try { //Hooks MetafileImageParsed event. WordDocument.MetafileImageParsed += OnMetafileImageParsed; WordDocument document = WordDocument.LoadString(param.content, GetFormatType(param.type.ToLower())); //Unhooks MetafileImageParsed event. WordDocument.MetafileImageParsed -= OnMetafileImageParsed; string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); return json; } catch (Exception) { return ""; } } return ""; } |
Regards,
Dhanush S
Attachment: ASP.NET_Core_d6519d46.zip
- 5 Replies
- 2 Participants
-
RM Robert Muresan
- Apr 29, 2025 06:21 PM UTC
- May 5, 2025 01:48 PM UTC