Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit fa1c31e

Browse files
authored
fpdf: allow to set global document language
The Document Catalog of a PDF allows to "specify the natural language for all text in the document" [1]. This is important to make PDFs accessible. This change allows to set the Lang entry in the document catalog. [1] PDF 1.7, section 7.7.2, page 74 https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf
1 parent 0e23f0a commit fa1c31e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

def.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ type Pdf interface {
479479
SetCreator(creatorStr string, isUTF8 bool)
480480
SetDashPattern(dashArray []float64, dashPhase float64)
481481
SetDisplayMode(zoomStr, layoutStr string)
482+
SetLang(lang string)
482483
SetDrawColor(r, g, b int)
483484
SetDrawSpotColor(nameStr string, tint byte)
484485
SetError(err error)
@@ -633,6 +634,7 @@ type Fpdf struct {
633634
title string // title
634635
subject string // subject
635636
author string // author
637+
lang string // lang
636638
keywords string // keywords
637639
creator string // creator
638640
creationDate time.Time // override for document CreationDate value

fpdf.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ func (f *Fpdf) SetAuthor(authorStr string, isUTF8 bool) {
605605
f.author = authorStr
606606
}
607607

608+
// SetLang defines the natural language of the document (e.g. "de-CH").
609+
func (f *Fpdf) SetLang(lang string) {
610+
f.lang = lang
611+
}
612+
608613
// SetKeywords defines the keywords of the document. keywordStr is a
609614
// space-delimited string, for example "invoice August". isUTF8 indicates if
610615
// the string is encoded
@@ -4892,6 +4897,9 @@ func (f *Fpdf) putinfo() {
48924897
func (f *Fpdf) putcatalog() {
48934898
f.out("/Type /Catalog")
48944899
f.out("/Pages 1 0 R")
4900+
if f.lang != "" {
4901+
f.outf("/Lang (%s)", f.lang)
4902+
}
48954903
switch f.zoomMode {
48964904
case "fullpage":
48974905
f.out("/OpenAction [3 0 R /Fit]")

0 commit comments

Comments
 (0)