Skip to main content
Inspiring
September 5, 2023
Answered

Error while text extracting from a textFrame.

  • September 5, 2023
  • 1 reply
  • 659 views

hi All,

I have been trying to extract text from a textframe as rtf format but I receive error while running it. The error is "The specified object does not support the desired export format". I tried with pdf and idml format and they worked well.

Any help or hint is appreciated.

 

var myDoc = app.activeDocument;
var myFrame = myDoc.textFrames.itemByName("India");
var myFile1 = new File(myDoc.filePath + "/" + "india.rtf"); // error on this line
var myFile2 = new File(myDoc.filePath + "/" + "india.pdf");
var myFile3 = new File(myDoc.filePath + "/" + "india.idml");

 

myFrame.exportFile(ExportFormat.RTF, myFile1);
myFrame.exportFile(ExportFormat.PDF_TYPE, myFile2);
myFrame.exportFile(ExportFormat.INDESIGN_MARKUP, myFile3);

alert("done");

This topic has been closed for replies.
Correct answer virender_CTS

It is working now with below code.

myFrame.parentStory.exportFile(ExportFormat.RTF, myFile1);

1 reply

Community Expert
September 5, 2023

See if this helps solve it

var myDoc = app.activeDocument;
var myFrame = myDoc.textFrames.itemByName("India");
var myText = myFrame.contents;
var myFile1 = new File(myDoc.filePath + "/" + "india.txt"); // Export as plain text

myFile1.open("w");
myFile1.write(myText);
myFile1.close();

var myFile2 = new File(myDoc.filePath + "/" + "india.pdf");
var myFile3 = new File(myDoc.filePath + "/" + "india.idml");

myFrame.exportFile(ExportFormat.PDF_TYPE, myFile2);
myFrame.exportFile(ExportFormat.INDESIGN_MARKUP, myFile3);

alert("Done exporting to PDF and IDML.");
Inspiring
September 5, 2023

Hi, thanks for the reply and sharing another alternative option however I intend to keep bold and italic formatting of text so RTF is required.

virender_CTSAuthorCorrect answer
Inspiring
September 5, 2023

It is working now with below code.

myFrame.parentStory.exportFile(ExportFormat.RTF, myFile1);