Is there a way to programmatically construct an Open Office document from two existing documents?
Asked Answered
X

1

0

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?

Xymenes answered 23/12, 2013 at 18:7 Comment(0)
G
2

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.

Gingili answered 23/12, 2013 at 19:34 Comment(8)
it just an idea you can make your pattern like &^ or (& or )^ any unique pattern and can place it at the end of document. make sure it does not exists anywhere other than at the end of the document.Gingili
and than you can break the string on the basic of your pattern like string exp = @"[\w\s\n\r\t\.()\,[]\-\;\:\%\@\#]*(?=&^)";Gingili
you can add the pattern at the footer of the page as well in case if its flow out to the next page . but i am not sure either you can read footer of the document file. please do check it. if yes than its more reliable to put the pattern at the footerGingili
At the end of the document (that would be better) or at the end of every page, as you state in your answer?Xymenes
By my update, I meant the addendum to my original post, not my editing of your answer from "Doc1Read" to "Doc2Read".Xymenes
At the end of the document (that would be better) or at the end of every page? Ans : It should be at the end of every page. As i suggested in my answer .Gingili
By my update, I meant the addendum to my original post, not my editing of your answer from "Doc1Read" to "Doc2Read" ? Yes I got your point, and I also answered of your update.Gingili
"It should be at the end of every page. As i suggested in my answer." Originally, but in a comment you then wrote, "can place it at the end of document" - that's why I questioned it.Xymenes

© 2022 - 2024 — McMap. All rights reserved.