Description
When setting document metadata (Author, Title, Subject, Creator, Keywords, Producer) using the corresponding Set* methods, the metadata is correctly stored and visible in the generated PDF.
However, as soon as PDF protection is enabled via SetProtection, all metadata except Producer appears encrypted / unreadable in PDF viewers. The Producer field remains as plain text.
This happens even though only printing protection is enabled and no password is set.
Steps to Reproduce
-
Create a minimal Go program using gofpdf:
package main
import "github.com/phpdave11/gofpdf"
func main() {
pdf := gofpdf.New("P", "mm", "A4", "")
// Set metadata
pdf.SetTitle("SetTitle", true)
pdf.SetAuthor("SetAuthor", true)
pdf.SetSubject("SetSubject", true)
pdf.SetCreator("SetCreator", true)
pdf.SetKeywords("SetKeywords", true)
pdf.SetProducer("SetProducer", true)
pdf.AddPage()
pdf.SetFont("Arial", "", 12)
pdf.Cell(40, 10, "Hello, world")
// Case 1: without protection
if err := pdf.OutputFileAndClose("no_protection.pdf"); err != nil {
panic(err)
}
// Case 2: with protection
pdf = gofpdf.New("P", "mm", "A4", "")
pdf.SetTitle("SetTitle", true)
pdf.SetAuthor("SetAuthor", true)
pdf.SetSubject("SetSubject", true)
pdf.SetCreator("SetCreator", true)
pdf.SetKeywords("SetKeywords", true)
pdf.SetProducer("SetProducer", true)
pdf.AddPage()
pdf.SetFont("Arial", "", 12)
pdf.Cell(40, 10, "Hello, world")
// Enable protection (printing only, no passwords)
pdf.SetProtection(gofpdf.CnProtectPrint, "", "")
if err := pdf.OutputFileAndClose("with_protection.pdf"); err != nil {
panic(err)
}
}
-
Open both no_protection.pdf and with_protection.pdf in a PDF viewer.
-
Inspect the document properties / metadata.
Expected Behavior
All metadata fields (Title, Author, Subject, Creator, Keywords, Producer) should remain readable and unchanged when enabling protection with SetProtection, since only permissions are being modified.
Actual Behavior
- In
no_protection.pdf, all metadata fields are displayed correctly as set:
- Title:
SetTitle
- Author:
SetAuthor
- Subject:
SetSubject
- Creator:
SetCreator
- Keywords:
SetKeywords
- Producer:
SetProducer
- In
with_protection.pdf, the following fields appear encrypted / unreadable:
- Title
- Author
- Subject
- Creator
- Keywords
- Only the
Producer field still appears as plain text (SetProducer).
Environment
- gofpdf version:
v1.4.3
- Go version:
go1.25.3
- OS: (macOS 26.1 Tahoe)
- PDF viewer(s) tested: Adobe Acrobat Reader DC, Apple Preview
Description
When setting document metadata (Author, Title, Subject, Creator, Keywords, Producer) using the corresponding
Set*methods, the metadata is correctly stored and visible in the generated PDF.However, as soon as PDF protection is enabled via
SetProtection, all metadata exceptProducerappears encrypted / unreadable in PDF viewers. TheProducerfield remains as plain text.This happens even though only printing protection is enabled and no password is set.
Steps to Reproduce
Create a minimal Go program using
gofpdf:Open both
no_protection.pdfandwith_protection.pdfin a PDF viewer.Inspect the document properties / metadata.
Expected Behavior
All metadata fields (
Title,Author,Subject,Creator,Keywords,Producer) should remain readable and unchanged when enabling protection withSetProtection, since only permissions are being modified.Actual Behavior
no_protection.pdf, all metadata fields are displayed correctly as set:SetTitleSetAuthorSetSubjectSetCreatorSetKeywordsSetProducerwith_protection.pdf, the following fields appear encrypted / unreadable:Producerfield still appears as plain text (SetProducer).Environment
v1.4.3go1.25.3