0

I am using Windows 10 and InDesign CS6. I would like to take 2 files, mix the content line by line and output to a third file to make an ebook, as follows.

INPUT FILE 1 (e.g. TXT, XML, SQL, etc.)

[This file is already in a line by line format -- each line is demarcated by a return.]

line 1

line 2

line 3

etc.

INPUT FILE 2 (INDD)

[This file is in the form of flowing text and each line will have to be demarcated e.g. 1 line = every text string that starts with capital letter and ends with "full stop + space".]

line A [footnote 1]

line B [footnote 2]

line C [footnote 3]

etc.

OUTPUT FILE 3 (e.g. EPUB, HTML, XML, etc.)

line 1

line A [footnote 1]

line 2

line B [footnote 2]

line 3

line C [footnote 3]

etc.

I found some relevant discussions here and here (the gist is that *nix systems have a paste function, Excel has a concertina function, and a method in the DOS command prompt and some other scripting methods were suggested). I am afraid these discussions are a bit cryptic for me and do not help my situation completely. I am computer literate but do not have coding experience so am looking for some help here to show me the way and get started.

Any suggestions for a reasonably practical work flow would be appreciated (it does not need to be completely automated). I'd also like to explore if Input File 1 was, say, a DOC or an INDD file of flowing, undemarcated text. It would be nice to have some flexibility in the workflow.

9
  • This is not going to be easy—there are so many unknowns and pitfalls in this kind of processing, most crucially (that I can think of): Are you certain there will always be the same number of lines in both files? Are you certain that all lines in file 2 can always be demarcated like that (what happens if a line contains something like “e.g. Microsoft”, for example)? Are the input files so long that manually separating file 2 into lines is prohibitive? If you can ensure accurate demarcation and identical number of lines, it shouldn’t be too hard to implement. May 21, 2017 at 11:22
  • It would still involve writing a reasonable complex InDesign script, though. JavaScript is probably the easiest and most popular of the languages supported. May 21, 2017 at 11:23
  • @JanusBahsJacquet i woundnt call the script complex
    – joojaa
    May 21, 2017 at 11:27
  • @joojaa That depends on how much it’s meant to do and how automated it has to be. If you need it to open the files without having the text in a document (i.e., choosing the input files in a prompt), then adding the content to the document and styling it according to rules not specified here, and then exporting the document as a complete ePub, that would in my world count as reasonably complex script for someone who has little to no coding experience. May 21, 2017 at 11:31
  • @JanusBahsJacquet sure, but then, you can always defend yourself that everything in the world is not worth doing since it could be done better. Best is the enemy of Done!
    – joojaa
    May 21, 2017 at 11:33

2 Answers 2

1

Yes, its a bit unfortunate that peoples computer literacy skills are in general as low as yours is. But that is normal I suppose. I would do it with my text editor or sed but that's just me. The answer put forth is quite straightforward. But lets do this in inDesign.

  1. Start inDesign and open a new document (and nothing else)
  2. Import
    1. contents of FILE 1 into one text frame
    2. contents of FILE 2 contents into another text frame
  3. Start ExtendScript Toolkit (if you have any adobe software installed then it gets installed).

    1. Choose File -> New JavaScript
    2. paste following into the document:

      #target indesign
      var doc = app.activeDocument;
      var text1 = doc.pages[0].textFrames[1].parentStory;
      var text2 = doc.pages[0].textFrames[0].parentStory;
      
      for(var p = text2.paragraphs.length-1; p >= 0 ; p--){
          text1.paragraphs[p].contents += text2.paragraphs[p].contents;
      }
      
    3. Hit the arrow labeled "start running..." to execute

That is about all there is for merging the lines. You can easily go much further but that's another thing entirely. Yes there is really no need to have a single human in a publishing pipeline, today.

Things to watch out for there ABSOLUTELY has to be a 1:1 correspondence between lines or this will fail. Also do not use this script in any other environment except a new document with just 2 frames.

6
  • Thank you. Ensuring a 1:1 correspondence is no problem e.g. for translations where we would expect this. Let's take a poem like Homer's Odyssey which has 12,110 Greek lines. Naturally, the English translation will also have 12,110 lines. The problem with the suggested solution is that they will not all fit in 1 text frame on 1 page so I hope threading of text frames is OK. Also, you said it is possible to go much further, so how can one specify the start and stop of each line e.g start with capital letter and end with full stop or line number? Will the footnotes be included?
    – Ad Astm
    May 21, 2017 at 19:44
  • @AdAstm does not matter for the script, its operating on the story level the only reason i need you to have 2 frames on the first page is simply that i can find handles to the stories. The fames themselves are irrelevant other than that. After they are combined you can do whatever you like with them.
    – joojaa
    May 21, 2017 at 19:50
  • I ran the script with different starting points and the following is what I found: ∙ the InDesign document must have 1 page · Frame 1 is the 1st frame to be drawn regardless of its position relative to the 2nd frame · the script takes the lines of Frame 2 and intersperses them between the lines of Frame 1, starting from the last line · the formatting of the lines of Frame 1 are retained. All formatting of the Frame 2 lines is lost to Frame 1 formatting · all footnotes are deleted, regardless of whether they were in Frame 1 or Frame 2 · works for non-Latin text too
    – Ad Astm
    May 22, 2017 at 11:31
  • Speaking strategically, which is what the question was about, I take it you think using the native InDesign script function is the way to go and that JavaScript is better for the purpose in the question than VBScript. Further, a JavaScript script should be built on the += operator.
    – Ad Astm
    May 22, 2017 at 11:58
  • @AdAstm VB script is fine but not portable between systems, and you must be admin to run it! Unless you buy a indesign server license. There is no difference otherwise, also server is just a extra pricey copy of indesign. Only if you must interact with the system at large. Strategically thinking you should hire a developer that had done this before.
    – joojaa
    May 22, 2017 at 13:03
0

Kasyan Servetsky kindly suggested that I use the move method and here is the result which appears to work fine...

#target indesign
var doc = app.activeDocument;
var text1 = doc.pages[0].textFrames[1].parentStory;
var text2 = doc.pages[0].textFrames[0].parentStory;

for(var p = text2.paragraphs.length-1; p >= 0 ; p--){
    text2.paragraphs[p].move(LocationOptions.AFTER, text1.paragraphs[p]);
}

So, the answer to the original question is to prepare the text of INPUT FILE 1 and INPUT FILE 2 within InDesign (two separate text frames on one page) and then run the above script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.