• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Duplicating a large number of pages script (special)

Explorer ,
Dec 30, 2016 Dec 30, 2016

Copy link to clipboard

Copied

A fairly common problem for us is having a large file, say ~100 pages, where we have to duplicate each page X number times, so that each duped page is added after the original.

For example: I have to duplicate each page of a 100 page file 5x so that in the end I have a file with pages in this order: 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3...

Normally when you duplicate 100 pages, it puts the pages at the end of the file. And while I know you can OPT-Drag pages to duplicate them where you want (in fact, I have a script with a shortcut to do this), many of our jobs are very large and it's not feasible to dupe 100 pages 5x each... 1 at a time. It's both too time consuming and introduces a large chance you'll make a mistake along the way.

Is there a script out there where you can quickly duplicate a large file in the order above? Or perhaps some trick to achieve the same result?

Thanks!

TOPICS
Scripting

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Dec 30, 2016 Dec 30, 2016

Hi,

You can try this snippet ...

var doc = app.documents[0];

var nbPage = doc.pages.length; // count doc pages

var n = 5; // duplicate number

for (i = 0; i < nbPage; i++) {

    var sourcePage = doc.pages.item(i + (i*n));

    for (j = 0; j < n; j++) {

        sourcePage.duplicate(LocationOptions.AFTER, doc.pages.item(i + (i*n)));

    }

}

Votes

Translate

Translate
Enthusiast ,
Dec 30, 2016 Dec 30, 2016

Copy link to clipboard

Copied

Hi,

You can try this snippet ...

var doc = app.documents[0];

var nbPage = doc.pages.length; // count doc pages

var n = 5; // duplicate number

for (i = 0; i < nbPage; i++) {

    var sourcePage = doc.pages.item(i + (i*n));

    for (j = 0; j < n; j++) {

        sourcePage.duplicate(LocationOptions.AFTER, doc.pages.item(i + (i*n)));

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 30, 2016 Dec 30, 2016

Copy link to clipboard

Copied

That's great - thank you!

While that is completely usable as is, is there any way to add a little popup so you can enter the number of duplicates you wanted?

Thanks again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 31, 2016 Dec 31, 2016

Copy link to clipboard

Copied

Like this ?

var n = prompt('Enter a number between 1 and 99.', '', 'Name of dialog');

var reg = /^\d{2}$/;

if (reg.test(n)){

    var doc = app.documents[0]; 

    var nbPage = doc.pages.length; // count doc pages 

     

    for (i = 0; i < nbPage; i++) { 

        var sourcePage = doc.pages.item(i + (i*n)); 

        for (j = 0; j < n; j++) { 

            sourcePage.duplicate(LocationOptions.AFTER, doc.pages.item(i + (i*n))); 

        } 

    } 

}else{

    alert('Error \r Must be a number between 1 to 99');

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

Oups my regex was wrong ...

var n = prompt('Enter a number between 1 and 99.', '', 'Name of dialog'); 

var reg = /^\d{1,2}$/;  

if (reg.test(n)){ 

    var doc = app.documents[0];   

    var nbPage = doc.pages.length; // count doc pages   

       

    for (i = 0; i < nbPage; i++) {   

        var sourcePage = doc.pages.item(i + (i*n));   

        for (j = 0; j < n; j++) {   

            sourcePage.duplicate(LocationOptions.AFTER, doc.pages.item(i + (i*n)));   

        }   

    }   

}else{ 

    alert('Error \r Must be a number between 1 to 99'); 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 03, 2017 Jan 03, 2017

Copy link to clipboard

Copied

That is *exactly* what I needed - THANK YOU!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2023 Dec 04, 2023

Copy link to clipboard

Copied

LATEST

you've just saved me a lot of time, thank you so much

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 30, 2016 Dec 30, 2016

Copy link to clipboard

Copied

I'm new to scripts, so here is my question. I have a large document of 1000 pages, each of them needing a different number of copies per page (from 2 - 6 copies ) do i create this script 5 times ?

Script 1 make 2 copies of this page... script 2 make 3 copies of this page... script 3 make 4 copies of this page?

This is way better than dragging with the Ctrl function.

Here is the task I have to do

 

Page copies
3884
3894
3902
3912
3921
3933
3942
3953
3962
3971
3985
3991
4001
4014
4023
4032
4043
4053
4064
4076
4084
4092
4102
4116
4123
4133
4144
4154
4166
4174
4181
4192
4202
4215
4226
4234
4243
4252
4265
4272
4284
4292
4301
4313
4322
4334
4346
4354
4362
4372
4382
4394
4403
4413
4425
4433
4443
4453
4462
4471
4485
4493
4502
4512
4522
4532
4541
4553
4562
4573
4584
4593
4602
4612
4621
4635
4644
4654
4663
4673
4683
4691
4703
4712
4722
4732
4744
4753
4761
4771
4782
4793
4804
4812
4821
4832
4844
4852
4865
4873
4882
4893
4904
4913
4923
4932
4943
4953
4964
4972
4985
4996
5002
5013
5021
5031
5041
5054
5063
5074
5085
5091
5103
5114
5125
5133
5143
5153
5165
5172
5181
5192
5203
5212
5223
5235
5245
5255
5261
5273
5283
5293
5304
5313
5323
5334
5345
5353
5364
5372
5386
5394
5403
5413
5423
5432
5442
5454
5463
5473
5482
5492
5504
5512
5524
5536
5542
5552
5561
5574
5585
5596
5604
5612
5625
5634
5642
5654
5661
5676
5685
5694
5705
5716
5721
5733
5743
5752
5763
5772
5782
5791
5804
5813
5822
5833
5846
5854
5861
5873
5884
5891
5904
5911
5925
5933
5944
5952
5962
5976
5983
5994
6002
6013
6025
6034
6044
6053
6061
6073
6081
6093
6106
6116
6123
6132
6142
6155
6166
6173
6183
6195
6202
6212
6224
6232
6241
6255
6262
6274
6283
6293
6304
6312
6324
6332
6342
6353
6363
6371
6383
6395
6402
6414
6422
6431
6443
6453
6463
6473
6483
6495
6502
6514
6526
6534
6541
6555
6562
6575
6581
6593
6605
6613
6622
6633
6645
6652
6663
6672
6684
6693
6703
6712
6722
6735
6743
6754
6761
6774
6786
6791
6801
6814
6826
6834
6841
6854
6863
6874
6882
6892
6902
6915
6921
6932
6941
6956
6961
6974
6983
6993
7004
7012
7022
7033
7045
7053
7062
7073
7082
7093
7103
7114
7123
7132
7143
7153
7163
7175
7183
7193
7205
7213
7221
7233
7245
7254
7262
7273
7281
7296
7302
7313
7323
7332
7346
7352
7364
7373
7382
7393
7403
7413
7421
7434
7444
7453
7466
7472
7483
7493
7505
7514
7523
7533
7545
7553
7561
7574
7582
7595
7602
7614
7622
7632
7642
7652
7663
7672
7683
7693
7702
7715
7722
7732
7744
7753
7765
7773
7784
7795
7803
7811
7823
7832
7843
7852
7864
7872
7883
7892
7902
7913
7921
7932
7943
7954
7965
7972
7982
7996
8003
8012
8023
8033
8046
8054
8064
8075
8082
8094
8104
8112
8123
8132
8143
8156
8162
8172
8186
8194
8201
8215
8223
8233
8245
8256
8264
8273
8283
8296
8304
8312
8324
8332
8343
8351
8363
8373
8383
8393
8404
8412
8424
8434
8444
8454
8461
8471
8485
8492
8502
8513
8521
8533
8542
8551
8564
8574
8583
8596
8603
8616
8624
8633
8641
8652
8661
8674
8681
8692
8703
8711
8722
8731
8742
8753
8762
8772
8784
8791
8803
8812
8822
8834
8842
8854
8862
8874
8886
8892
8903
8912
8925
8936
8942
8952
8962
8971
8985
8995
9002
9016
9022
9033
9046
9051
9066
9072
9085
9093
9103
9114
9124
9134
9143
9154
9162
9174
9184
9193
9203
9216
9224
9233
9244
9253
9264
9272
9282
9293
9302
9316
9321
9332
9344
9352
9362
9374
9382
9393
9402
9413
9421
9432
9443
9454
9464
9476
9481
9496
9502
9512
9525
9535
9543
9554
9563
9573
9586
9596
9602
9615
9622
9631
9643
9656
9662
9672
9683
9693
9701
9713
9725
9732
9742
9755
9761
9773
9782
9792
9806
9814
9824
9832
9843
9852
9862
9872
9883
9894
9906
9912
9924
9933
9942
9954
9962
9972
9984
9993
10003
10015
10022
10034
10043
10054
10062
10072
10084
10092
10102
10113
10123
10133
10143
10154
10163
10171
10183
10193
10202
10214
10225
10234
10242
10253
10265
10273
10282
10294
10301
10314
10325
10334
10342
10353
10362
10373
10384
10391
10403
10411
10423
10433
10442
10452
10462
10471
10485
10491
10505
10512
10523
10534
10544
10554
10561
10573
10581
10594
10603
10615
10624
10632
10643
10651
10662
10674
10685
10695
10704
10715
10722
10733
10741
10752
10762
10774
10783
10795
10803
10812
10824
10834
10845
10851
10865
10874
10883
10891
10905
10914
10922
10934
10942
10951
10964
10972
10983
10992
11005
11013
11022
11034
11042
11055
11063
11076
11082
11093
11104
11113
11122
11132
11143
11153
11162
11175
11185
11193
11205
11213
11224
11232
11243
11254
11264
11275
11282
11291
11301
11312
11323
11333
11342
11353
11362
11374
11382
11395
11404
11412
11422
11433
11446
11456
11462
11476
11481
11494
11503
11511
11526
11535
11545
11552
11562
11573
11583
11593
11606
11612
11625
11634
11643
11652
11663
11673
11682
11693
11703
11713
11722
11732
11742
11753
11763
11772
11783
11793
11802
11812
11821
11833
11844
11854
11865
11876
11882
11893
11903
11913
11923
11936
11941
11954
11965
11975
11981
11993
12002
12012
12024
12031
12041
12053
12064
12072
12082
12095
12104
12112
12121
12131
12142
12153
12163
12172
12184
12194
12205
12215
12223
12231
12243
12253
12265
12272
12281
12294
12302
12315
12323
12334
12342
12354
12362
12374
12381
12391
12405
12413
12423
12431
12442
12454
12461
12477
12484
12491
12504
12515
12522
12531
12542
12553
12562
12572
12581
12592
12601
12614
12626
12635
12643
12651

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines