unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.48k stars 250 forks source link

[BUG] Big paragraph overflows page #409

Closed Grehgous closed 3 years ago

Grehgous commented 3 years ago

Description

What a paragraph is larger than fits on a single page, a blank page is added, however the text is not distributed between the two pages. It ends up with one empty page, one page that is overflowed, and the remaining text missing.

Expected Behavior

I expect the text to be distributed to new pages whenever a page is overflowed, and not to have any empty pages added

Attachments

c := creator.New()
c.SetPageMargins(50, 50, 100, 70)

// Write text larger than the page
p := c.NewParagraph(strings.Repeat("foo ", 3000))
_ = c.Draw(p)

// Save the PDF ...

output.pdf

github-actions[bot] commented 3 years ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

adrg commented 3 years ago

Hi @Grehgous

You can use creator.StyledParagraph to achieve this, instead of creator.Paragraph.

package main

import (
    "log"
    "strings"

    "github.com/unidoc/unipdf/v3/creator"
)

func main() {
    c := creator.New()
    c.SetPageMargins(50, 50, 100, 70)

    p := c.NewStyledParagraph()
    p.Append(strings.Repeat("foo ", 3000))

    if err := c.Draw(p); err != nil {
        log.Fatal(err)
    }
    if err := c.WriteToFile("out.pdf"); err != nil {
        log.Fatal(err)
    }
}
gunnsth commented 3 years ago

@Grehgous Have you tried the suggested solution? Would be good to update the ticket so it can be closed or further investigation done.