Ckeditor / WYSIWYG copy from pdf and save style / images?

I searched a lot but could not get an answer.

I want to keep the copied text from pdf

to WYSIWYG editor

(Ckeditor). I can keep the style when copying from Word files, but it doesn't work the same way when copying from pdf

.

The original pdf

is similar to this one (I cannot post the image as it is rep < 10

, see links):

PDF text enter image description here

It shows the following output after copying:

After copying in WYSIWYG editor enter image description here

Please suggest a plugin or code snippet for converting PDF to RTF.

thank

+3


source to share


3 answers


CKEditor can only insert data that it receives from browsers. This means that if browsers do not provide more data, then there is nothing CKEditor can do in plain text.

Since version 4.5 CKEditor provides a facade for handling the clipboard API and gets all the data that is inserted directly into the event paste

. Each browser provides different data and you can check it easily:

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 an array types

and only supports the Text

and types URL

.

To learn more about clipboard integration, see this tutorial . Especially in the "Handling Different Types of Data with the Clipboard API" section, which describes how to integrate a data converter with paste, so if the PDF data is available in any browser, you can use it when you paste.

+5


source


If this is a common case on your system, then the best thing you can do is allow users to download the PDF, run the server side software to convert the PDF to HTML, and then automatically insert it into CKEditor.



I have no recommendation though on which app to use.

+3


source


The problem is that PDF files work differently than other text documents, so even if you try to paste its content into a native word processor, you won't get the same formatting.

It depends on your PDF reader, but usually that no images are inserted, tables are converted to plain text strings, etc.

If this happens in a native program that has full buffer access, you cannot expect anything better in a javascript application that depends on the data the browser provides, and even after that, you need to be careful with CKEditor because it includes filters by default to remove any formatting that it doesn't recognize, so even more information could be lost at that last point.

+1


source







All Articles