Documentation
¶
Overview ¶
Package render is the orchestrator that turns a kardec.Document into a PDF byte stream. It plugs three internal subsystems together:
- internal/layout walks the Document tree, breaks lines, places blocks
- internal/typography resolves font faces and provides text measurement
- internal/pdf writes the final PDF 1.7 byte stream
Importing this package wires Document.Render / RenderTo / Bytes via an init() hook in kardec; the public surface here is therefore optional — users can call render.ToFile / ToWriter / Bytes directly, or rely on the method API after a blank import:
import (
"github.com/arthurhrc/kardec"
_ "github.com/arthurhrc/kardec/render"
)
The indirection avoids an import cycle: kardec cannot import internal/layout because layout already imports kardec to walk the document tree.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes ¶
Bytes renders d as a PDF and returns the bytes. Convenient for tests and HTTP handlers that buffer responses.
Example ¶
ExampleBytes shows the in-memory render path: build a Document, call render.Bytes, and inspect the resulting PDF byte stream. The output is asserted as the PDF magic header so godoc shows a runnable, deterministic example.
package main
import (
"fmt"
"github.com/arthurhrc/kardec"
"github.com/arthurhrc/kardec/render"
)
func main() {
doc := kardec.New(kardec.PageA4, kardec.MarginsNormal).
Heading(1, kardec.Text("Monthly Report")).
Paragraph(
kardec.Text("Sales grew "),
kardec.Bold("12%"),
kardec.Text(" this quarter."),
)
out, err := render.Bytes(doc.Document)
if err != nil {
fmt.Println("render error:", err)
return
}
fmt.Println("PDF starts with:", string(out[:8]))
}
Output: PDF starts with: %PDF-1.7
func ToFile ¶
ToFile renders d as a PDF and writes it to path. The file is created (or truncated) and closed before ToFile returns.
Example ¶
ExampleToFile writes the document to a path. Errors from os.Create or the underlying renderer surface through the returned error.
package main
import (
"github.com/arthurhrc/kardec"
"github.com/arthurhrc/kardec/render"
)
func main() {
doc := kardec.New(kardec.PageA4, kardec.MarginsNormal).
Paragraph(kardec.Text("Hello, file."))
_ = doc // build steps
_ = render.ToFile // render.ToFile(doc.Document, "out.pdf")
}
Output:
Types ¶
This section is empty.