Reputation: 586
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
Upvotes: 0
Views: 118
Reputation: 586
The code was correct from the beginning.
After some tests we observed the follow behaviors:
Conclusion
So base on our tests we concluded that something was wrong with that particular field in that particular file. Creating another version of the file resolved the problem.
Upvotes: 0
Reputation: 1
It looks like you are trying to redefine a const variable, therefore if it is set to false it will always be false.
Best regards Tyler
Upvotes: 0