I searched a lot but couldn't get the answer.
I want to retain copied text from pdf to WYSIWYG editor(Ckeditor).
I can retain style while copied from Word files but it does not work the same way when copied from PDF.
Original pdf is like this(I can't post image as reputation is < 10 , please refer links):
PDF text
It shows following output after copy paste:
After copy paste in WYSIWYG editor
Please suggest plugin or code snippet for PDF to RTF conversion.
Thanks
CKEditor can paste only data which it gets from the browsers. It means that if browsers do not provide more data then the plain text there is nothing CKEditor can do.
Since version 4.5 CKEditor provide facade to handle Clipboard API and get all data which are pasted directly in the paste event. Every browser provide different data and you can easily check them:
editor.on( 'paste', function( evt ) {
var types = evt.data.dataTransfer.$.types;
console.log( types );
for ( var i = 0; i < types.length; i++ ) {
console.log( evt.data.dataTransfer.getData( types[ i ] ) );
}
// Additionally you can get information about pasted files.
console.log( evt.data.dataTransfer.getFilesCount() );
} );
Note that Internet Explorer does not provide types array and support only Text and URL types.
To learn more about Clipboard Integration see this guide. Especially "Handling Various Data Types with Clipboard API" chapter which describe how to integrate data converter with the paste event, so if the PDF data are available in any browser you can use them during pasting.
If it's a common case in your system then imho the best thing you can do is to allow users to upload the PDF file, run server side software to transform PDF into HTML and then automatically insert it into CKEditor.
I have no recommendations though on which application to use.
The problem is that PDF files work in a different way that other text documents, so even if you try to paste its contents into a native word processor you won't get the same formatting.
This will vary depending on your PDF reader, but it's usual that images aren't pasted, tables are converted to plain text lines, etc...
If that happens in a native program that has full access to the clipboard, you can't expect anything better in a javascript application that depends on the data that the browser provides, and even after that you have to be careful with CKEditor because by default it includes filters to remove any formatting that it doesn't recognize so even more information can be lost at this last point.
Related
I'm new with this and not certain what platform to use to achieve my desired outcome (i.e. php, javascript, etc.), but I'm a fast learner.
I add videos to my YouTube channel daily. After this I update two separate webpages where I manually embed the newest video URL.
Question:
I would like to automate this work process. What is the best approach (i.e. CSS, Javascript, PHP, etc.) that I can use to "get" the most current YouTube video URL and embed it into my webpage(s) automatically?
I hope I explained this properly. Let me know if you need any additional information. Thanks in advance for any guidance you can offer!!!
(1) Get link of latest video on your Channel:
You can request from Youtube, a Channel's feed using
https://www.youtube.com/feeds/videos.xml?channel_id=XXXXX
Where XXXXX is the channel's ID (as shown in browser's address bar).
The first entry in the XML document is the latest video.
Use Javascript Fetch API to load the XML or else have a JS function to call a PHP script that gives/reads back this XML document.
After correct loading, you'll have a String (text) copy of that same document existing in some variable that you put it into. The idea here is to edit the text by code (instead of highlighting and replacing the URL in a text editor). The code should find and replace the URL. The code should then save the edited text as a new HTML file (overwrite the old one using PHP)
With Javascript, either use its String functions to extract the URL or follow some tutorial about parsing XML to extract data.
(2) To update the webpages: (use PHP)
Option 1 is to load the old page and use PHP String functions to replace text of old link with latest new link. Then write the edited text as file (overwrite older HTML file)
Option 2 is to have a "template" document already stored as String in your code. Then simply replace (or add if needed) the URL of new video. Then have PHP save the text of String as an HTML file, overwriting the old .html.
Use this service, I think it will be the easiest way: https://latestyoutu.be/
You can find your channel ID by clicking Settings, Advanced, and Account Information and paste it into the site. (https://support.google.com/youtube/answer/3250431). This is probably the most hassle-free way of doing what it seems you want to.
According to this Microsoft dev guidance, it should be possible to have a element on a web page do a POST via the method=POST attribute of the form. It shows an example of HTML needed in order to open a report viewer to a report and render the HTML viewer. I have that working. I would like to use the exact same technique to create a PDF or Excel file, but it doesn't work when I update the Format parameter to either PDF or EXCELOPENXML. Instead it ignores that parameter and provides the HTML viewer anyway. I would like to stick to one technique for both opening the HTML viewer and for downloading the various file formats. Does anyone know a workaround? I have considered a generic function to take the hidden elements and tack them on to the action URL, and open a new window with that. Does anyone have the code to do that?
I would still be curious to know if there's an issue with the POST action for file exports, but in the meantime, I solved it with this:
$("form").find(":input[name]").map(function(val, key) {
return encodeURIComponent($(this).attr('name'))
+ '='
+ encodeURIComponent($(this).val()).replace(/%2C/g,',').replace(/%20/g,' ');
//unencode space and comma characters for convinience and shorter URLs
}).get().join("&")
I have a use-case where I want my application to store clipboard data and later allow the user to paste it out.
The thing is - I want to both support HTML-styled text (while maintaining its styling) and also support simple plain-text.
What I have so far is:
Pasteboard variable setup
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.html, .string], owner: nil)
Storing user's clipboard data
let copiedString = pasteboard.string(forType: .html) ?? pasteboard.string(forType: .string) {
If, for example, a user copies text from the browser, this method maintains the entire HTML.Alternatively, if text is being copied from applications that don't support HTML (such as XCode, Notes, etc), `copiedString` will simply hold the plain text.
Later down the line - pushing contents back to clipboard
pasteboard.setString(copiedString, forType: .html)
My problem is, when I try to paste the content pushed into my clipboard; it only works in applications that actually support HTML-formatted text, such as Chrome / Microsoft Word.
When I try to paste the content into XCode for example, it simply doesn't spit out anything.
Ideally, I want my clipboard to adjust itself according to the application I'm on - paste the text as HTML if supported by the application, otherwise - paste the plain text.
How can I implement such behavior?
Thanks!
I was wondering if it was possible and what exactly I would need to loop through a list of url links and save those pages as pdfs. I would like to create a script that could do this but not sure how realistic it is.
Example:
www.site1.com
- save pdf locally site1.pdf
www.site2.com
- save pdf locally site2.pdf
It is realistic, although it needs a bit coding, as saving HTML pages as PDF files is not that simple.
There are libraries like FPDF or mPDF for PHP that can convert a HTML doc into a valid pdf, but it will not take a 'screenshot' of the page, but rather build it from the HTML tags and the CSS. They even allow changing the CSS file to your custom one.
(If you want to take a screenshot there is always PHP's imagegrabscreen(), but it will only work on a Windows server.)
You will just have to fetch the dom from your url:
$html = file_get_contents('http://site1.com');
Convert it to a pdf with one of the mentioned libraries, and save it as a file:
$mpdf = new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
See:
http://fpdf.org
http://mpdf1.com
(I personally prefer mPDF - it is based on FPDF and has a nice and easy API.)
Pretty much just the question. I have a client that is requesting a negative design with nearly white text all over the webpage, but testers are saying that it's annoying to copy and paste from the website as everything shows up as white text when copying into Word or the like.
Is there a way to either preemptively remove formatting when a user tries to copy text from the website? Or is there a way to hijack what actually gets put on the clipboard?
Ctrl + alt + v or ctrl +shift + v should paste what's on your clipboard as unformatted text. Very handy for copying code samples to word docs. This should also work on Mac if you substitute cmd for Ctrl
Using code from both here Javascript: Hijack Copy? and here Get the Highlighted/Selected text (thanks #Jacque Goupil) I was able to piece together the following code that strips the formatting from anything copied on the page:
$("body").bind('copy', function(e) {
var newEl = document.createElement("p");
document.body.appendChild(newEl);
if (window.getSelection) {
newEl.innerHTML = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
newEl.innerHTML = document.selection.createRange().text;
}
var selection = document.getSelection();
var range = selection.getRangeAt(0);
selection.selectAllChildren(newEl);
setTimeout(function() {
newEl.parentNode.removeChild(newEl);
selection.removeAllRanges();
selection.addRange(range);
}, 0)
});
What goes in the clipboard by default depends on the browser. Text processors like Microsoft Word usually have options to ignore pasted style, so it shouldn't be an issue if they learn how to use it properly.
If you still want to make life easier for people, you could detect copy events and replace the formated text with raw text. This might help you:
How do I copy to the clipboard in JavaScript?
Get the Highlighted/Selected text
In Word you've got the option to 'Paste as plain text' (or 'Paste without formatting', not sure of the exact name in English). That way, you can easily paste text from any website without markup.
I don't think it should be the responsibility of the website to implement a 'copy without markup'.
Other trick: paste text with markup in Notepad first. Then select it in Notepad and copy again. The clipboard now contains only plain text.
Of course it's hard to educate the users, but unless there is a very good reason why people would be copying texts from the website, I wouldn't make a custom implementation for it. Those implementations, especially when you override default behaviour (capture Ctrl+C), will probably not work well or at least the same in every browser, and they are just a fix for your website, not everyone else's. Also, such a feature might annoy other users who do know how to handle text with mark-up. So I think it's better to let the users figure out themselves.
As for hijacking the clipboard, if you copy HTML, the browser actually copies the content in multiple formats, like HTML, RTF and plain text. If you had the means, you could simply remove the HTML and RTF version from the clipboard and let the plain text version remain. But I'm pretty sure you don't have that much control over the clipboard from the browser.