0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GoでPDFを作成する

Posted at

はじめに

表題通り、GoでPDFを作成する記事となります。

成果物

ディレクトリ構成
~/go/src/go_pdf$ tree
.
├── example.pdf
├── go.mod
├── go.sum
└── main.go

1 directory, 4 files
main.go
package main

import (
	"fmt"

	"github.com/jung-kurt/gofpdf"
)

func main() {
    // PDFを新規作成
    pdf := gofpdf.New("P", "mm", "A4", "")
    pdf.AddPage()

    // フォントの設定
    pdf.SetFont("Arial", "B", 16)
    pdf.Cell(40, 10, "Hello World")

    // ファイルに保存
    err := pdf.OutputFileAndClose("example.pdf")
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println("PDFファイルが作成されました。")
}

→実行すると、example.pdfが作成されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?