THotPDF 已加载表单字段编辑方法
在既有 AcroForm 中更新字段约束与 widget 外观字典,同时保持增量保存与渲染缓存正确
原生字段标志编辑保留完整的 32 位掩码,包括高位和低位常用标志,并沿用既有的已加载字段继承规则
有符号掩码值、继承与原生构建器行为见AcroForm 字段标志精度
字段级方法
procedure SetLoadedFormFieldFlags(FieldIndex, AFlags: Integer);
procedure SetLoadedFormFieldMaxLength(FieldIndex, AMaxLength: Integer);
procedure SetLoadedFormFieldJustification(FieldIndex: Integer;
AJustification: THPDFFormFieldJustification);
procedure SetLoadedFormFieldTooltip(FieldIndex: Integer; const ATooltip: AnsiString);SetLoadedFormFieldFlags替换完整的 PDF/Ff位掩码SetLoadedFormFieldMaxLength写出/MaxLen;零或负值移除限制THPDFFormFieldJustification含ffjLeft、ffjCenter、ffjRight,对应 PDF/Q值 0 到 2
用 SetLoadedFormFieldJustification 设置字段对齐,再用 EnsureLoadedFieldAppearanceStream 重新生成外观;已加载 listbox 标签遵循生效的 /Q 值,而不改变 /TI 窗口或已存储的选中项
控件几何
function GetLoadedFormFieldWidgetCount(FieldIndex: Integer): Integer;
function GetLoadedFormFieldWidgetRect(FieldIndex, WidgetIndex: Integer;
out ARect: THPDFRect): boolean;
procedure SetLoadedFormFieldWidgetRect(FieldIndex, WidgetIndex: Integer;
X1, Y1, X2, Y2: Single);- 字段与控件索引从 0 开始
- 控件枚举暴露 radio 组和其他多控件字段的每个
/Kids条目 - 矩形端点使用原始 PDF 用户空间点,写入前归一化
控件外观与可见性
procedure SetLoadedFormFieldRotation(FieldIndex, ADegrees: Integer);
procedure SetLoadedFormFieldBorderColor(FieldIndex: Integer;
ARed, AGreen, ABlue: Single);
procedure SetLoadedFormFieldVisibility(FieldIndex: Integer;
AVisible, APrintable: boolean);
procedure SetLoadedFormFieldBorderWidth(FieldIndex: Integer; AWidth: Single);
procedure SetLoadedFormFieldBackgroundColor(FieldIndex: Integer;
ARed, AGreen, ABlue: Single);- 旋转接受 90 度的正负倍数,存储归一化的
/MK /R值 - 边框与背景 RGB 分量钳制到 PDF DeviceRGB 的 0 到 1 范围
- 外观与可见性 setter 更新所选字段的每个控件
- 可见性在控制 Hidden、NoView 与 Print 的同时保留无关的注释标志
增量更新行为
- 字段、控件、
/MK与/BS字典在各自值存储的层级上标脏 - 视觉变化只使受影响页面的缓存 DPI 变体失效
- 无效的字段或控件索引使文档保持不变
示例
PDF.BeginIncrementalUpdate('input.pdf');
PDF.SetLoadedFormFieldMaxLength(0, 40);
PDF.SetLoadedFormFieldJustification(0, ffjCenter);
PDF.SetLoadedFormFieldRotation(0, 90);
PDF.SetLoadedFormFieldBorderColor(0, 0.1, 0.4, 0.8);
PDF.SetLoadedFormFieldWidgetRect(1, 1, 80, 150, 100, 170);
PDF.SaveIncrementalUpdate('updated.pdf');