Copy link to clipboard
Copied
Hi, After a long absence I am doing some InDesign JavaScript scripting on Windows with ID 2020. I have a document that someone is supplying me and I have to import text into it. I want to make sure that there is no existing text in the document and that any extra pages beyond page 1 are deleted. I figured out how to select all of the text but I am not sure how to delete it. Thank you in advance.
textFrame = doc.textFrames[0];
textFrame.parentStory.texts[0].select ();
// Not sure what to do here.
doc.selection.remove ();
It looks like this is what I need:
// Delete all body page content.
textFrame = doc.textFrames[0];
textFrame.parentStory.texts[0].contents = "";
Copy link to clipboard
Copied
Try the following
for(var i = app.documents[0].pages.length - 1; i > 0 ; i--)
{
app.documents[0].pages[i].remove();
}
app.documents[0].textFrames.everyItem().remove()
-Manan
Copy link to clipboard
Copied
Thank you for the reply. I need to delete the text first or else it autoflows and adds the pages back in. I know how to select the text, but I don't know how to remove it. Thanks.
Copy link to clipboard
Copied
It looks like this is what I need:
// Delete all body page content.
textFrame = doc.textFrames[0];
textFrame.parentStory.texts[0].contents = "";
Copy link to clipboard
Copied
Hi frameexpert,
if I understand this right, in principle you want to remove all stories of the document.
And you want to restrict the number of pages of that document to the first one.
app.documents[0].stories.everyItem().remove();
app.documents[0].documentPreferences.pagesPerDocument = 1;
If you want to remove all text frames from spread one as well, you need additional code.
Also if you want not to remove text from master spreads.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Yes, thank you. I want to keep the first text frame so that I can import fresh context into the file. The template developer sometimes leaves sample content in the document.