How can I edit an Acrobat pdf with JavaScript?

39 Views Asked by At

I need to assign a name to a form field in a Acrobat pdf. I am using JavaScript but I can't see the field . pdfLib does not show any fields in the pdf. I know the field is there because I have used it for years. I need to automate the process but I can't see the form field. Any ideas on solving this problem?

Here is what I tried:

    // Fill out the form fields
    const form = mergedPdf.getForm();
    
    const nameField = form.getFieldMaybe('Name');
    if (nameField) {
        nameField.setText(studentName);
    }
    
    const dateField = form.getFieldMaybe('Date');
    if (dateField) {
        dateField.setText(new Date().toLocaleDateString());
    }

    // Serialize the PDF to bytes (Uint8Array)
    const mergedPdfBytes = await mergedPdf.save();

    const fieldNames = form.getFields().map(f => f.getName());
    console.log(`Fields in merged PDF for ${studentName}:`, fieldNames);
0

There are 0 best solutions below