Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TextFields with same fieldName, ie. TextFieldGroups #3821

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imjosh
Copy link

@imjosh imjosh commented Feb 4, 2025

A use case for this feature is multi-page documents with fields that are duplicated on each page (e.g. name and date on medical forms). Resolves #3361

Also, upgrade "rollup-plugin-terser" from 6.1.0 to 7.0.2 for optional chaining support.

Let me know if you'd like me to submit a pull request that combines this one with #3813

Example:
jsPdf

var { TextFieldGroup } = jsPDF.AcroForm;

var doc = new jsPDF({
  format: "a6",
  orientation: "landscape",
  unit: "mm",
  floatPrecision: 2
});

var txtName = new TextFieldGroup();
txtName.fieldName = "Name";
doc.addField(txtName);

var txtDate = new TextFieldGroup();
txtDate.fieldName = "Date";
doc.addField(txtDate);

addHeader();
doc.addPage();
addHeader();

function addHeader() {
  let yPos = 9;
  let xPos = 5;
  let txtChild;

  doc.text("Name:", xPos, yPos);
  xPos += doc.getTextWidth("Name:") + 1;
  txtChild = txtName.createChild();
  txtChild.Rect = [xPos, yPos - 6, 60, 9];

  xPos += 70;

  doc.text("Date:", xPos, yPos);
  xPos += doc.getTextWidth("Date:") + 1;
  txtChild = txtDate.createChild();
  txtChild.Rect = [xPos, yPos - 6, 35, 9];

  yPos += 5;
  doc.line(0, yPos, doc.internal.pageSize.width, yPos);
}

@imjosh imjosh marked this pull request as ready for review February 4, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for AcroForm textFields with same fieldName
1 participant