Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boxesandglue/bagme
boxes and glue made easy - a PDF rendering library for Go using boxes and glue
https://github.com/boxesandglue/bagme
css go html pdf pdf-generation
Last synced: 7 days ago
JSON representation
boxes and glue made easy - a PDF rendering library for Go using boxes and glue
- Host: GitHub
- URL: https://github.com/boxesandglue/bagme
- Owner: boxesandglue
- License: bsd-3-clause
- Created: 2022-11-17T08:33:03.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-15T09:14:04.000Z (3 months ago)
- Last Synced: 2024-08-15T10:49:14.732Z (3 months ago)
- Topics: css, go, html, pdf, pdf-generation
- Language: Go
- Homepage:
- Size: 90.8 KB
- Stars: 71
- Watchers: 8
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: License.md
Awesome Lists containing this project
README
# bagme - boxes and glue made easy
bagme is a PDF library to format HTML fragments styled with CSS using the (pure Go) “[boxes and glue](https://boxesandglue.dev)” library.
boxes and glue implements TeX's typesetting algorithms, so the idea is to get superb HTML rendering with almost no effort.The goal is to have a PDF rendering engine for your Go software without having to do a lot of programming.
## Sample code
```go
package mainimport (
"log""github.com/boxesandglue/bagme/document"
"github.com/boxesandglue/boxesandglue/backend/bag"
)var html = `
The frog king
In olden times when wishing still helped one,
there lived a king whose daughters were all beautiful,
but the youngest was so beautiful that the sun itself,
which has seen so much, was
astonished whenever it
shone in her face.Close by the king's castle lay a great dark forest,
`
and under an old lime-tree in the forest was a well,
and when the day was very warm, the king's child
went out into the forest and sat down by the side of
the cool fountain, and when she was bored she took a
golden ball, and threw it up on high and caught it,
and this ball was her favorite plaything.var css = `
body {
font-family: serif;
font-size: 12pt;
line-height: 14pt;
}p {
margin-top: 8pt;
margin-bottom: 2pt;
}.green {
color: green;
}#important {
color: rebeccapurple;
font-weight: bolder;
font-style: italic;
}`func dothings() error {
d, err := document.New("out.pdf")
if err != nil {
return err
}
if d.AddCSS(css); err != nil {
return err
}
// loads the font families serif, sans and monospace
if err = d.Frontend.LoadIncludedFonts(); err != nil {
return err
}
wd := bag.MustSP("280pt")
colText := bag.MustSP("140pt")
colImage := bag.MustSP("20pt")
rowText := bag.MustSP("23cm")
if err = d.OutputAt(html, wd, colText, rowText); err != nil {
return err
}if err = d.OutputAt(``, wd, colImage, rowText); err != nil {
return err
}
return d.Finish()
}func main() {
if err := dothings(); err != nil {
log.Fatal(err)
}
}
```## Limitations
* No automatic page breaks: you have to take care of your items on the page.
* Limited HTML/CSS support: some things are implemented, most are not.You can take a look at [the examples repository](https://github.com/boxesandglue/bagme-examples) to see what is possible.
## Other
Contact:
License: New BSD License
Status: Beta: You can try it, but expect API changes.
Mastodon: [[email protected]](https://typo.social/@boxesandglue)