インストール
必要要件
- Go 1.22 以降
- 外部依存は不要
インストール
go get github.com/gpdf-dev/gpdf
モジュール設定
go.mod にgpdfを追加します:
module your-project
go 1.22
require github.com/gpdf-dev/gpdf v1.0.4
gpdfは外部依存ゼロ — Go標準ライブラリのみを使用します。CGo不要、システムライブラリ不要、複雑なビルドステップもありません。
インストールの確認
package main
import (
"fmt"
"github.com/gpdf-dev/gpdf/document"
"github.com/gpdf-dev/gpdf/template"
)
func main() {
doc := template.New(template.WithPageSize(document.A4))
page := doc.AddPage()
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("gpdf is working!")
})
})
data, err := doc.Generate()
if err != nil {
panic(err)
}
fmt.Printf("Generated PDF: %d bytes\n", len(data))
}
go run main.go
# Output: Generated PDF: 1234 bytes
パッケージ構成
gpdfは3つのレイヤーで構成されています。必要なものだけインポートしてください:
import (
"github.com/gpdf-dev/gpdf" // Facade (再エクスポート)
"github.com/gpdf-dev/gpdf/template" // Layer 3: Builder API, コンポーネント
"github.com/gpdf-dev/gpdf/document" // Layer 2: 型定義, スタイル, 単位
"github.com/gpdf-dev/gpdf/pdf" // Layer 1: カラー, PDFプリミティブ
)
| パッケージ | レイヤー | 用途 |
|---|---|---|
template | 3 | Builder API, JSONスキーマ, Goテンプレート, コンポーネント |
document | 2 | ページサイズ, 単位 (Mm, Pt 等), スタイル, ノードタイプ |
pdf | 1 | カラー (RGB, Hex, Gray), PDF Writer, フォント埋め込み |
qrcode | — | QRコード生成 |
barcode | — | バーコード生成 (Code 128) |