I'm loading a PDF document and I need to be sure that each field whose name has a certain pattern gets converted to a COMB field. Happens that a field can be duplicated, meaning that is possible to find another field with the same.
For each field...
const fieldChanged = await PDFNet.runWithCleanup(() => combFieldAdjustmentCallBack(pdfField, configuredMaxLen), this.configurationService.webViewerPDFTronKey);
combFieldAdjustmentCallBack implementation
const combFieldAdjustmentCallBack = async (pdfField: Core.Annotations.Forms.Field, configuredMaxLen: number) => { let fieldChanged: boolean; const itr = await pdfDoc.getFieldIterator(pdfField.name); for (; await itr.hasNext(); await itr.next()) { const docField = await itr.current(); // if the field has not set the flag comb; set it and mark the field as changed const comb = await docField.getFlag(PDFNet.Field.Flag.e_comb); if (!comb) { await docField.setFlag(PDFNet.Field.Flag.e_multiline, false); await docField.setFlag(PDFNet.Field.Flag.e_password, false); await docField.setFlag(PDFNet.Field.Flag.e_no_spellcheck, true); await docField.setFlag(PDFNet.Field.Flag.e_no_scroll, true); await docField.setFlag(PDFNet.Field.Flag.e_rich_text, false); await docField.setFlag(PDFNet.Field.Flag.e_comb, true); const comb = await docField.getFlag(PDFNet.Field.Flag.e_comb); // Always "Field XYZ is a comb field: false" console.log(`Field ${pdfField.name} is a comb field: ${comb}`); fieldChanged = true; } // Set max length const currentMaxLength = await docField.getMaxLen(); if (configuredMaxLen != currentMaxLength) { await docField.setMaxLen(configuredMaxLen); fieldChanged = true; } if (fieldChanged) { docField.refreshAppearance(); } return fieldChanged ?? false; } };
This logic works when the field happens only once, but doesn't work when the field repeats across the PDF. Please, note Always "Field XYZ is a comb field: false
What I'm missing