Letter
Overview
The Letter component generates a formal business letter PDF with sender/recipient headers, date, subject, body paragraphs, and signature block.
Usage
import "github.com/gpdf-dev/gpdf/template"
doc := template.Letter(template.LetterData{
From: template.LetterParty{
Name: "ACME Corporation",
Address: []string{
"123 Business Street",
"Suite 100",
"San Francisco, CA 94105",
"contact@acme.com",
},
},
To: template.LetterParty{
Name: "Mr. John Smith",
Address: []string{
"Tech Solutions Inc.",
"456 Client Avenue",
"New York, NY 10001",
},
},
Date: "March 1, 2026",
Subject: "Partnership Proposal",
Greeting: "Dear Mr. Smith,",
Body: []string{
"I am writing to express our interest in establishing a strategic partnership " +
"between ACME Corporation and Tech Solutions Inc. Over the past year, we have " +
"observed the remarkable growth of your organization and believe that a collaboration " +
"would be mutually beneficial.",
"Our proposal includes joint development of cloud-based solutions targeting " +
"the enterprise market. ACME Corporation brings extensive experience in PDF " +
"generation and document processing, while Tech Solutions Inc. has demonstrated " +
"excellence in frontend technologies and user experience design.",
"We would like to schedule a meeting at your earliest convenience to discuss " +
"the details of this proposal. Please feel free to contact me directly at " +
"ceo@acme.com or call our office at (415) 555-0100.",
},
Closing: "Sincerely,",
Signature: "Jane Doe",
SignerTitle: "Chief Executive Officer",
})
data, err := doc.Generate()
┌─ A4 ──────────────────────────────────────────────┐
│ │
│ ACME Corporation │
│ 123 Business Street │
│ Suite 100 │
│ San Francisco, CA 94105 │
│ contact@acme.com │
│ │
│ March 1, 2026 │
│ │
│ Mr. John Smith │
│ Tech Solutions Inc. │
│ 456 Client Avenue │
│ New York, NY 10001 │
│ │
│ RE: Partnership Proposal │
│ ──────────────────────────────────────────────── │
│ │
│ Dear Mr. Smith, │
│ │
│ I am writing to express our interest in │
│ establishing a strategic partnership between │
│ ACME Corporation and Tech Solutions Inc... │
│ │
│ Our proposal includes joint development of │
│ cloud-based solutions targeting the enterprise │
│ market... │
│ │
│ We would like to schedule a meeting at your │
│ earliest convenience to discuss the details... │
│ │
│ │
│ Sincerely, │
│ │
│ Jane Doe │
│ Chief Executive Officer │
│ │
└───────────────────────────────────────────────────┘
Data Types
LetterData
| Field | Type | Description |
|---|---|---|
From | LetterParty | Sender information |
To | LetterParty | Recipient information |
Date | string | Letter date |
Subject | string | Subject line |
Greeting | string | Opening greeting (e.g., "Dear Mr. Smith,") |
Body | []string | Body paragraphs |
Closing | string | Closing phrase (e.g., "Sincerely,") |
Signature | string | Signer name |
SignerTitle | string | Signer title |
LetterParty
type LetterParty struct {
Name string
Address []string
}
Customization
Pass document options to customize the letter:
fontData, _ := os.ReadFile("fonts/NotoSansJP-Regular.ttf")
doc := template.Letter(letterData,
template.WithFont("NotoSansJP", fontData),
template.WithDefaultFont("NotoSansJP", 12),
template.WithPageSize(document.Letter),
)
Using the Facade
import "github.com/gpdf-dev/gpdf"
doc := gpdf.NewLetter(letterData)