A computer system comprising: a processor ; and a computer readable storage medium having stored thereon program code that, when executed by the processor , causes the processor to: receive an indication of a starting point for a page in a content flow of a document; build a DOM (Document Object Model) tree of content elements in a portion of the content flow spanning from the starting point to an estimated ending point, wherein the estimated ending point corresponds to a location in the content flow that is a predefined number of content elements after the starting point, the predefined number of content elements being an estimated number of content elements that can fit on a given page, with a certain amount of overflow onto the next page; invoke an API (application programming interface) that causes a layout engine of a web browser to create a layout of the page based on the DOM tree; determine, based on the layout and the content flow , one or more content elements in the content flow that fall beyond an actual ending boundary of the page; remove the one or more content elements from the DOM tree; and add the DOM tree to a page set for the document. a processor ; and a computer readable storage medium having stored thereon program code that, when executed by the processor , causes the processor to: receive an indication of a starting point for a page in a content flow of a document; build a DOM (Document Object Model) tree of content elements in a portion of the content flow spanning from the starting point to an estimated ending point, wherein the estimated ending point corresponds to a location in the content flow that is a predefined number of content elements after the starting point, the predefined number of content elements being an estimated number of content elements that can fit on a given page, with a certain amount of overflow onto the next page; invoke an API (application programming interface) that causes a layout engine of a web browser to create a layout of the page based on the DOM tree; determine, based on the layout and the content flow , one or more content elements in the content flow that fall beyond an actual ending boundary of the page; remove the one or more content elements from the DOM tree; and add the DOM tree to a page set for the document. receive an indication of a starting point for a page in a content flow of a document; build a DOM (Document Object Model) tree of content elements in a portion of the content flow spanning from the starting point to an estimated ending point, wherein the estimated ending point corresponds to a location in the content flow that is a predefined number of content elements after the starting point, the predefined number of content elements being an estimated number of content elements that can fit on a given page, with a certain amount of overflow onto the next page; invoke an API (application programming interface) that causes a layout engine of a web browser to create a layout of the page based on the DOM tree; determine, based on the layout and the content flow , one or more content elements in the content flow that fall beyond an actual ending boundary of the page; remove the one or more content elements from the DOM tree; and add the DOM tree to a page set for the document. <EOS>