admin管理员组文章数量:1388748
I'm using pdf-lib in a Node.js project to fill out a secured PDF form that contains a radio button group with custom export values and appearance dictionaries. The PDF is encrypted (password-protected), but I can load and modify it fine. When I call .select()
on the radio group, the underlying field value updates correctly, but the visual appearance does not change—it remains stuck on the default appearance.
Here's a minimal example:
const fs = require('fs');
const { PDFDocument } = require('pdf-lib');
async function fillForm() {
// Load the encrypted PDF form (password: 'secret')
const pdfBytes = fs.readFileSync('form.pdf');
const pdfDoc = await PDFDocument.load(pdfBytes, { password: 'secret' });
const form = pdfDoc.getForm();
// Get the radio group field (custom export values: 'CreditCard', 'PayPal', 'WireTransfer')
const paymentMethod = form.getRadioGroup('PaymentMethod');
// Select the "CreditCard" option
paymentMethod.select('CreditCard');
// Attempt to update field appearances
form.updateFieldAppearances();
const pdfBytesUpdated = await pdfDoc.save();
fs.writeFileSync('filled.pdf', pdfBytesUpdated);
}
fillForm();
Even though paymentMethod.select('CreditCard')
updates the field value, the visual appearance remains unchanged—the radio button does not reflect the "CreditCard" selection. This happens even after calling form.updateFieldAppearances()
. The PDF's radio button group uses custom appearance dictionaries for each option.
How can I force pdf-lib to update the appearance of a radio button group with custom export values in an encrypted PDF so that the selection is visually reflected? Has anyone encountered this issue with custom appearance dictionaries not being redrawn after a .select()
call?
UPDATE: The documentation warns that pdf-lib doesn’t support modifying encrypted PDFs reliably, and while unencrypted files work fine, encrypted ones don’t. Since the file must stay encrypted, a workaround is suggested: decrypt the file, perform your edits, and then save it with a new password.
This is valuable if you have access to setting pdf permissions - if not, no answer is yet provided.
本文标签: javascriptRadio button group appearance not updating for custom export valuesStack Overflow
版权声明:本文标题:javascript - Radio button group appearance not updating for custom export values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744608537a2615510.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论