How to delete blank pages in a multipage document?

后端 未结 2 1862
臣服心动
臣服心动 2021-01-24 16:32

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 Henriqu

2条回答
  •  失恋的感觉
    2021-01-24 16:46

    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 :)

提交回复
热议问题