Question

I have two documents, one in Spanish and one in English (the English is a translated version of the original in Spanish). I am creating a third document from the two, which includes the Spanish on each evenly numbered page, and the corresponding English translation on the opposite odd-numbered page.

I am using up the entire page on both sides except at the end of a chapter (each new chapter gets a page break, so it can start at the top of the page). Admittedly, in order to use up the entire page, there are occasions where portions of the text are on the next page (that is to say, the English translation of what appears at the bottom of page 18 in Spanish on occasion appears at the top of page 21, rather than at the bottom of page 19).

I am currently manually doing the following to accomplish this, with all three Open Office documents open (Spanish.odt, English.odt, and SpanishEnglish.odt):

0) Cut and paste exactly one page of material from Spanish.odt to the next (even-numbered) page of SpanishEnglish.odt
1) Mash the Enter key to move to the next (odd-numbered) page
2) Cut and paste exactly one page of material from English.odt to the next (odd-numbered) page of SpanishEnglish.odt
3) Mash the Enter key to move to the next (even-numbered) page

Also, periodically (when the chapter end is reached), I insert a Page Break; if the end of the chapter doesn't fit on one page for either the Spanish or English (while the other does, of course) in SpanishEnglish.odt, I reduce the font size of the too-long page (from Verdana 10 to Verdana 9) to force it to constrain itself to that page, so that the chapters begin side-by-side (Spanish on the left/even, English on the right/odd) without having any blank pages.

As you can doubtless imagine -- especially with a large document, which this is -- this procedure gets very tedious very quickly. Is there a way to programmatically accomplish the same thing in C#?

UPDATE

Shujaat Siddiqui, I assume you mean change these last lines:

The Dangerous Pelican Movie
. . .
La película de los pelícanos peligrosos

...to this:

The Dangerous Pelican Movie&&&&
. . .
La película de los pelícanos peligrosos&&&&

...by appending "&&&&" to the last line - Correctomundo? But in many cases this additional text ("&&&&") will push the contents to the next page (one or more of the ampersands will flow onto the following page), no?

Was it helpful?

Solution

Its bit Tricky. I am trying to give you just the basic idea.

  1. Just write &&&& at the end of every page. In English doc as well as in Spanish doc.
  2. now use regex to break text from &&&&. Its like reading the doc page by page.

Here is a sample code just to give you the basic logic.

            string Doc1Read  = //read from english file
            string Doc2Read = // read from Spanish file


                string exp = @"[\w\s\n\r\t\.\(\)\,\[\]\-\;\:\%\@\#]*(?=&&&&)";

                var Doc1matches = Regex.Matches(Doc1Read, exp);
                var Doc2matches = Regex.Matches(Doc2Read, exp);
                for (int i = 0; i < Doc1matches.Count; i++)
                {
                    **// open third document file and write** 

                    Doc1matches[i].Value; // write english version of page i
                    Doc2matches[i].Value; // write spanish version of page i

                }

&&&& is used to get the text page by page . In this way when you use Doc1matches[i].Value;you basically get what is written on page number i i.e {1,2,3...}.

Hope it helped you.

PS : You can also use string.Split("&&&&"); to break the string from &&&&. and can implement the logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top