| 4145 | } |
| 4146 | |
| 4147 | function _drawOptionList(page, field, rect, font) { |
| 4148 | let selected = []; |
| 4149 | try { |
| 4150 | selected = field.getSelected?.() || []; |
| 4151 | } catch { |
| 4152 | selected = []; |
| 4153 | } |
| 4154 | |
| 4155 | if (!Array.isArray(selected)) { |
| 4156 | selected = [selected].filter(Boolean); |
| 4157 | } |
| 4158 | |
| 4159 | if (!selected.length) return; |
| 4160 | |
| 4161 | const lines = selected.map((v) => String(v)); |
| 4162 | const fontSize = Math.max( |
| 4163 | 8, |
| 4164 | Math.min(11, rect.height / Math.max(lines.length + 0.5, 2)) |
| 4165 | ); |
| 4166 | const lineHeight = fontSize + 1.5; |
| 4167 | |
| 4168 | let y = rect.y + rect.height - fontSize - 2; |
| 4169 | |
| 4170 | for (const line of lines) { |
| 4171 | if (y < rect.y + 1) break; |
| 4172 | |
| 4173 | page.drawText(line, { |
| 4174 | x: rect.x + 2, |
| 4175 | y, |
| 4176 | size: fontSize, |
| 4177 | font, |
| 4178 | color: rgb(0, 0, 0), |
| 4179 | maxWidth: Math.max(1, rect.width - 4) |
| 4180 | }); |
| 4181 | |
| 4182 | y -= lineHeight; |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /** Remove only Widget annotations; preserve links, stamps, comments, etc. */ |
| 4187 | function _removeWidgetAnnotations(pdfDoc) { |