Skip to main content
Participant
March 11, 2019
Answered

Delete duplicate pages of data merge

  • March 11, 2019
  • 1 reply
  • 979 views

Hello everyone

I'm working on an editorial project to create agendas. I am using data merge to create the pages with calendar data, however due to a project specialty the data merge creates the duplicate pages.

I need to create a script that I can automatically remove from two pages from a page number specified by me.

I tell scrip that two pages he starts deleting, he deletes these two, jumps two and deletes the next two and continues until the document is finished.

Can someone help me?

This topic has been closed for replies.
Correct answer crazyPanda

Hi,

first things first: create a backup of your document before you run this script.

Second: insert in line 3 the index number of the page from where it should start the deleting process. The index number is 1 less than the page number. For example: if you want to start from page number 5 the value of startPage should be 4.

var doc = app.activeDocument;

var startPage = "insert start value";

var currentPage = startPage;

while (currentPage < doc.pages.length)

{

     doc.pages[currentPage].remove();

     if (currentPage <= doc.pages.length)

          {

               doc.pages[currentPage].remove();

          } else {exit();}

currentPage = currentPage +2;

}

1 reply

crazyPanda
crazyPandaCorrect answer
Participating Frequently
March 11, 2019

Hi,

first things first: create a backup of your document before you run this script.

Second: insert in line 3 the index number of the page from where it should start the deleting process. The index number is 1 less than the page number. For example: if you want to start from page number 5 the value of startPage should be 4.

var doc = app.activeDocument;

var startPage = "insert start value";

var currentPage = startPage;

while (currentPage < doc.pages.length)

{

     doc.pages[currentPage].remove();

     if (currentPage <= doc.pages.length)

          {

               doc.pages[currentPage].remove();

          } else {exit();}

currentPage = currentPage +2;

}

alfredohdAuthor
Participant
March 12, 2019

Thank you again. The script worked perfectly. My project is ready to be finalized and I owe a lot to you.