Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8066107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:52:33+00:00 2026-06-05T11:52:33+00:00

EDIT : added an answer because edit would have been to long (see answer2)

  • 0

EDIT : added an answer because edit would have been to long (see answer2)

Following a former post about document merging I ended up with a working script (Thanks Henrique 😉 but I still have one small issue : the final ‘merged’ document contains sometimes blank pages (depending of other docs content) that I would like to remove.
I cannot find an easy way to do this.
The script goes like this :

function mergeDocs(docIDs) {  // parameter docIDs is an array of Doc IDs
  var baseDocname = DocumentApp.openById(docIDs[0]).getName();// typical name = IMPRESSION_page_07_07-06-2012__20:57
  var modelDoc = DocsList.getFileById(docIDs[0]);
  var newmodelName=baseDocname.substr(0,11)+'multipage'+baseDocname.substring(18);
  var baseDocId = DocsList.copy(modelDoc,newmodelName).getId();// make a copy of firstelement and give it new basedocname build from the serie(to keep margins etc...)
  var baseDoc = DocumentApp.openById(baseDocId)
  var body = baseDoc.getActiveSection();
//
  for( var i = 0; i < docIDs.length; ++i ) {
    var otherCopy = DocumentApp.openById(docIDs[i]).getActiveSection();
    var totalElements = otherCopy.getNumChildren();
    for( var j = 0; j < totalElements; ++j ) {
      var element = otherCopy.getChild(j).copy();
      var type = element.getType();
      if( type == DocumentApp.ElementType.PARAGRAPH )
        body.appendParagraph(element);
      else if( type == DocumentApp.ElementType.TABLE )
        body.appendTable(element);
      else if( type == DocumentApp.ElementType.LIST_ITEM )
        body.appendListItem(element);
      else
        throw new Error("According to the doc this type couldn't appear in the body: "+type);
    }
     body.appendPageBreak(); // if content length is too short avoids breaking page layout
  }
}

The ‘PageBreak’ causes (sometimes) a blank page , I know that(!), but it is necessary to keep a perfect page layout (I’m printing labels with this doc).
here is a link to a typical example

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:52:35+00:00Added an answer on June 5, 2026 at 11:52 am

    Well Serge, I don’t think there’s anything on the API to tell which page an element belongs. So, solving this will be tricky 🙂

    Right of the bat, I think of an “inside” approach. I mean, you know which page is giving you trouble. If it is always the same (e.g. you have a fixed number of labels), you could just loop counting the page breaks and remove the bad one.

    But if that’s no possible, which is my guess, at least you know your layout. You could test to see how many labels fit a page exactly and then count your labels, so that when it happens, you skip appending the page-break. That looks like a better solution.

    Then again, depending on your layout, that might not be possible or just too difficult. So, the last thing I can think of is to check the Document DOM to see if any specific pattern happens when a page-break is alone on a page. Since that’s kind of weird, I guess Google Docs probably automatically inserts an empty paragraph on this page, so it’s not “childless”, or something like it, maybe even a property, I don’t know. What I know is that this will require a good amount of effort, doing an investigation to understand deeply how the Document DOM works. If you don’t do it, I’ll probably have to in the future as I work with document as templates like this a lot. When I do I’ll update my answer, if you haven’t done it before me 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT : Accepted answer points out what my issue was. I added another answer
I have a piece of code: EDIT: The _penParams are initialized as the added
Edit: Added code (Exception on line 095, 5th time it's hit.) public DataTable ParseBarcodes(String[]
EDIT: I added in where I create new instance of the class Process as
EDIT I added this note to explain why I keep this question here. I
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: Now a Major Motion Blog Post at http://messymatters.com/sealedbids The idea of rot13 is
I have an app that I made with wxglade. I've added a mediacontrol to
See the following SQL statement: SELECT datediff(d, MAX(invoice.date), Now) As Date_Diff , MAX(invoice.date) AS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.