mozilla/pdf.js · error · Error
doc.producer is read-only
Error message
doc.producer is read-only
What it means
`Doc.producer` returns the producer string from the PDF metadata (`this._producer`), populated when the document is parsed. It is a factual metadata attribute and read-only per the Acrobat spec — changing it would misrepresent the file's origin. PDF.js's throwing setter enforces that; scripts cannot overwrite the producer.
Source
Thrown at src/scripting_api/doc.js:607
set path(_) {
throw new Error("doc.path is read-only");
}
get permStatusReady() {
return true;
}
set permStatusReady(_) {
throw new Error("doc.permStatusReady is read-only");
}
get producer() {
return this._producer;
}
set producer(_) {
throw new Error("doc.producer is read-only");
}
get requiresFullSave() {
return false;
}
set requiresFullSave(_) {
throw new Error("doc.requiresFullSave is read-only");
}
get securityHandler() {
return this._securityHandler;
}
set securityHandler(_) {
throw new Error("doc.securityHandler is read-only");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Remove the assignment; read `doc.producer` only (`var p = doc.producer;`).
- Perform metadata edits at the PDF-generation/processing layer (the producer is set by the creating application).
- Run legacy scripts through try/catch to tolerate the write attempt.
Example fix
// before doc.producer = 'Custom Producer'; // after var p = doc.producer; // read-only metadata
Defensive patterns
Strategy: validation
Validate before calling
const READ_ONLY_DOC_PROPS = new Set(['producer','subject','title','author','creator','keywords' /* ... */]);
function assertsNoReadOnlyWrite(scriptSrc) {
for (const p of READ_ONLY_DOC_PROPS) {
if (new RegExp(`\\bdoc\\.${p}\\s*=[^=]`).test(scriptSrc)) {
throw new Error(`Script writes read-only property doc.${p}`);
}
}
}
assertsNoReadOnlyWrite(myScript); Type guard
function isReadOnlyDocProp(doc, prop) {
const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(doc), prop)
|| Object.getOwnPropertyDescriptor(doc, prop);
return !!desc && !!desc.get && !desc.set;
}
isReadOnlyDocProp(doc, 'producer'); // true Try / catch
try {
doc.producer = 'Custom';
} catch (e) {
if (/producer is read-only/.test(e.message)) console.warn(e.message);
else throw e;
} Prevention
- Metadata fields are read-only in PDF.js scripting; edit metadata at PDF generation time.
- Maintain and lint against a list of read-only metadata properties.
- Wrap branding/metadata scripts in try/catch for legacy tolerance.
When it happens
Trigger: A script writes `doc.producer = 'MyApp';` to brand or alter metadata. The setter throws on assignment.
Common situations: Scripts that try to rewrite metadata on save; branding workflows ported from Acrobat; code that assumes metadata setters exist.
Related errors
- doc.subject is read-only
- doc.title is read-only
- doc.mouseX is read-only
- doc.mouseY is read-only
- doc.numFields is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/06aab14b19040882.
Report an issue: GitHub.