Skip to main content
Participating Frequently
January 19, 2011
Question

Hw could copy a unformatted text from a formated paragraph

  • January 19, 2011
  • 1 reply
  • 818 views

Dear all,

I am trying to copy an unformatted text from a formatted paragraph i have a code snippet, Please check it out and tell me that how can i copy a unformatted text from a paragraph. Result of this script should be a unformatted selected text...

var par = app.selection[0].paragraphs[0];

    if (app.selection[0] instanceof InsertionPoint)

        {

        if (par.characters[-1].contents != "\r")

            par.insertionPoints[-1].contents = "\r";

            par.characters.itemByRange(app.selection[0], par.insertionPoints[-1]).select();

            app.copy();

         }

        else

         {

            par.characters.itemByRange(app.selection[0], par.insertionPoints[-1]).select();

            app.copy();

          }

This topic has been closed for replies.

1 reply

Robin_dvAuthor
Participating Frequently
January 19, 2011

Dear all

Indesign have a built in function to do this.

Application.pasteWithoutFormatting ()

Pastes data (minus formatting) from the clipboard into the active document window.

Inspiring
January 19, 2011

It's not the copy that 'removes' formatting, it's the paste that pastes without.

Text can exist on the clipboard in any number of internal formats. It's possible to copy InDesign formatted text and paste it into a plain text editor -- so you won't get the formatting. But if you paste the same text again in InDesign, the formatting is still there.

When copying, it's the responsibility of the copying program to put its copyable content in any useful format onto the global Clipboard.

When pasting, a program should go through the list of supplied data formats (regardless of the source) and pick whatever it thinks is best. So, apparently, the usual Paste picks up InDesign "Native objects", while "Paste w/o Formatting" uses the plain (unformatted) text form.

The only way to get an unformatted copy on the pasteboard would be to copy the string contents (raw ASCII characters) instead -- but InDesign's Javascript does not allow this. The app.copy() command only works on native InDesign objects.

So, long story short, what you need can't be done.

Robin_dvAuthor
Participating Frequently
January 19, 2011

Thanks Jongware