Skip to main content
Participant
September 18, 2024
Question

how can I copy a master-page as a new page in the same document?

  • September 18, 2024
  • 2 replies
  • 295 views
 

I have a master page:

var master = doc.masterSpreads.itemByName("B-Parent");

I want that as a new page after my last page. I dont want that new page have that assigned master page "B-Parent", I want that new page be a copy of the master-page, having all items the master page has itself, but not the Items that the master-page inherits from its master-page:

So, if B-Parent has some text-frames and and an image and has itself the A-Parent as master which has some background etc., the new page should end up mastered by A-parent (B-Parents master) and should have a copy of B-Parents text-frames and its image.

How can I do that?

var master = doc.masterSpreads.itemByName("B-Parent");
var newPage = app.activeDocument.pages.add();
/*
... how can I copy the content of master into newPage? ...
*/
newPage.appliedMaster = master.appliedMaster;
This topic has been closed for replies.

2 replies

brian_p_dts
Community Expert
Community Expert
September 18, 2024

Apply Parent A, then do use the .override function function for every pageItem on B. 

Pseudocode is: 

var mb = Parent B

 

Edit: Duh that won't work since B isn't applied. You'll need to distinguish the B items from the A items, maybe through layer naming or labels, then iterate through those and duplicate them to newPage

for allPageItems on mb, api[i].override(newPage)

 

Robert at ID-Tasker
Legend
September 18, 2024

Select everything on the B-Parent, copy, paste-in-place on the newly created page, apply A-Parent. 

 

Of course, you can apply master first - doesn't matter. 

 

Just recreate steps that you would've to do manually.