lib/origami/page.rb in origami-1.2.4 vs lib/origami/page.rb in origami-1.2.5

- old
+ new

@@ -2,10 +2,14 @@ = File page.rb = Info + This file is part of Origami, PDF manipulation framework for Ruby + Copyright (C) 2010 Guillaume Delugré <guillaume AT security-labs DOT org> + All right reserved. + Origami is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -23,12 +27,20 @@ class PDF def append_page(page = Page.new, *more) raise InvalidPDFError, "Invalid page tree" if not self.Catalog or not self.Catalog.Pages or not self.Catalog.Pages.is_a?(PageTreeNode) - pages = [ page ].concat(more) + pages = [ page ].concat(more).map! do |pg| + if pg.pdf and pg.pdf != self + # Page from another document must be exported. + pg.export + else + pg + end + end + treeroot = self.Catalog.Pages treeroot.Kids ||= [] #:nodoc: treeroot.Kids.concat(pages) treeroot.Count = treeroot.Kids.length @@ -40,9 +52,12 @@ self end def insert_page(index, page) raise InvalidPDFError, "Invalid page tree" if not self.Catalog or not self.Catalog.Pages or not self.Catalog.Pages.is_a?(PageTreeNode) + + # Page from another document must be exported. + page = page.export if page.pdf and page.pdf != self self.Catalog.Pages.insert_page(index, page) self end