github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/creator/pagebreak.go (about) 1 package creator 2 3 // PageBreak represents a page break for a chapter. 4 type PageBreak struct { 5 } 6 7 // NewPageBreak create a new page break. 8 func NewPageBreak() *PageBreak { 9 return &PageBreak{} 10 } 11 12 // GeneratePageBlocks generates a page break block. 13 func (p *PageBreak) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) { 14 // Return two empty blocks. First one simply means that there is nothing more to add at the current page. 15 // The second one starts a new page. 16 blocks := []*Block{ 17 NewBlock(ctx.PageWidth, ctx.PageHeight-ctx.Y), 18 NewBlock(ctx.PageWidth, ctx.PageHeight), 19 } 20 21 // New Page. Place context in upper left corner (with margins). 22 ctx.Page++ 23 newContext := ctx 24 newContext.Y = ctx.Margins.top 25 newContext.X = ctx.Margins.left 26 newContext.Height = ctx.PageHeight - ctx.Margins.top - ctx.Margins.bottom 27 newContext.Width = ctx.PageWidth - ctx.Margins.left - ctx.Margins.right 28 ctx = newContext 29 30 return blocks, ctx, nil 31 }