How to Merge Multiple Google Documents

You can use Google Apps Script to merge two or more Google Documents into a single document. The script takes the first document and appends the content of all the other documents into this document. All the formatting, tables, lists and other elements are preserved in the merged document.

Update: [Merijn Peeters] My document included a very big table, and when merging several of those documents, a blank line was added from the second page onward. This corrupted the layout, of course.

After hours of searching, I discovered that the error was due to the fact that the ‘appendTable’ function automatically appends a blank paragraph as well, because a document cannot end with a table. From Google’s documentation:

appendTable() – Creates and appends a new Table – This method will also append an empty paragraph after the table, since Google Docs documents cannot end with a table.