Skip to main content
Known Participant
August 10, 2012
Answered

Importing MS docs to odd pages only

  • August 10, 2012
  • 1 reply
  • 1182 views

About a year ago I got some help from John Hawkinson (thanks again!) with a script to import word documents to multiple pages with the same master page. That discussion can be found here: http://forums.adobe.com/message/3732719#3732719

I would now like to modify this script to apply it only to the one side of a series of two page spreads using the same master page spread. In other words, let's say I have 300 facing pages that use A-Master. I would like to import 150 pages into the odd (right hand side) pages of the spread (page 1.doc gets imported to page 1, page2.doc gets imported to page 3, page 3.doc gets imported to page 5, etc.).

Is there any easy way to do this?

Thanks,

Neil

This topic has been closed for replies.
Correct answer Jongware

> I think I would need separate counters--one for the word doc numbers and another god the INDD page where it is imported.

Oui mon frère, I was overseeing the "page number" thingy was re-used in John's script to select a numbered Word file.

Quick-and-ever-so-slightly-dirty: re-use the loop (page) counter but divide it by two! (.. and add 1 because loops run from zero upwards).

frames.textFrames[2].place(new File("/path/to/page"+String((i>>1)+1)+".doc"));

I prefer to use the >> operator here, rather than division, because Javascript is scrupulous about its divisions and dividing an odd number such as '3' by 2 will result in 1.5. Logical, but nasty. Bit shifting the value 3 to the right ibehaves like "divide, round down" -- the lowest bit just gets lost.

Fortunately, you don't have odd numbers in your loop *here* but hey, you might want to repurpose this script for odd numbered pages!

1 reply

Jongware
Community Expert
Community Expert
August 10, 2012

Neil Weinberg wrote:

Is there any easy way to do this?

At a glance,

for (i=0; i<p.length; i+=2)

ought to work.

[Edit] Gah! There is color, bold, and underlining to mark my change -- but this **** *** forum software does not show it!

The minor change is 'i++' to 'i+=2'. Given some time, I can explain why.)

Saki HAuthor
Known Participant
August 10, 2012

Thanks for your help. Would that work, even though the word documents are numbered sequentially (i.e., not odd numbers only)?

In other words page2.doc needs to be imported on page 3 in the INDD file, page3.doc on page 5, page4.doc on page 7, etc.

I think I would need separate counters--one for the word doc numbers and another god the INDD page where it is imported.

Thanks,

Neil

Envoyé de mon iPhone

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
August 10, 2012

> I think I would need separate counters--one for the word doc numbers and another god the INDD page where it is imported.

Oui mon frère, I was overseeing the "page number" thingy was re-used in John's script to select a numbered Word file.

Quick-and-ever-so-slightly-dirty: re-use the loop (page) counter but divide it by two! (.. and add 1 because loops run from zero upwards).

frames.textFrames[2].place(new File("/path/to/page"+String((i>>1)+1)+".doc"));

I prefer to use the >> operator here, rather than division, because Javascript is scrupulous about its divisions and dividing an odd number such as '3' by 2 will result in 1.5. Logical, but nasty. Bit shifting the value 3 to the right ibehaves like "divide, round down" -- the lowest bit just gets lost.

Fortunately, you don't have odd numbers in your loop *here* but hey, you might want to repurpose this script for odd numbered pages!