Вот минимальный пример:
Код: Выделить всё
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();
Подробнее здесь: https://stackoverflow.com/questions/795 ... ort-values