将PDF导出为XML并使用Delphi填充标记

问题描述 投票:-1回答:1

没有一些帮助我无法解决这个问题。

我正在尝试使用Acrobat Reader中的正确菜单将PDF文档导出为XML / XDP。

我可以在Acrobat Reader中看到文档中的所有字段,并且可以使用Delphi的代码填充它们,除了3个标记。

当我尝试将字段的内容导出到XML时,问题出现了,并且XML不包含它应该包含的三个字段标记。它们根本不在Acrobat Reader生成的XML中,但正如我所说,这些字段确实可用,而不是隐藏在PDF表单本身中。

例如 :

姓名:<Name></Name>

名字:<Firstname></Firstname>

日期:缺少XML文件

什么可以解释这三个字段不会导出到XML而其他所有字段都是这样的事实,我怎么能调查差异的原因是什么?

我希望我能给你足够的信息来帮助我。

xml delphi pdf acrobat
1个回答
1
投票

我不愿意将此作为答案发布,因为它不会直接回答您的问题,但它可能会指出您正确的方向做一些自助。

除非您的PDF文件已损坏,否则这是对您的3个问题字段的唯一合理解释,而且它只能与存储在PDF文件中的属性有关。正如您从下面的Acrobat Formms界面的摘录中看到的那样,每个字段都有大量可能的属性,我相信您应该能够找出解决问题字段不同行为的差异。 。

AFORMAUTLib_TLB.Pas是我从Acrobat8的Forms插件生成的导入单元(现在有点老了,但我觉得不重要)。它的摘录显示了Acrobat IField的界面以及可以为Acrobat表单中的字段设置的无数属性/属性。

所以,在你的位置,如果我绝对不得不使用Reader生成的XML,我会做的是使用AFORMAUTLib_TLB中的对象编写一些代码来转储表单字段的属性,看看我是否可以识别那里的任何差异在你的三个问题领域和其他领域之间。使用AFORMAUTLib_TLB中的对象非常简单 - 基本上,有一个FormApp对象允许您打开Acrobat表单并提供对其IFields集合的访问,该集合包含表单上定义的每个字段的IField实例。所有这些都在Adobe网站提供的Acrobat SDK中进行了详细记录。

如果你花一两个小时玩Forms界面,我很确定你最终会被诱惑避免使用Reader的XML输出,只是从表单中的IField对象生成你自己的。这假设你当然真的需要XML。

我想 - 但是不确定(并且不想安装Reader以查明)是Acrobat Reader是否具有用于处理字段的相同插件。显然,如果没有,那么你对这种方法运气不好。

祝好运!

PS:一旦你有一个感兴趣的领域的IField接口,你可以在运行时调整它的属性和内容,所以如果你能找到引起问题的差异,那么应用一个非常简单的方法。运行时修复。

另外btw导入单元中的接口对象可以很容易地将普通PDF文档转换为表单并可选择填写它,这就是你需要的东西。我不确定是否已采取任何措施来抑制Reader中的这一功能 - 如果你开始做很多表格工作,那么完整版Acrobat的副本就是必不可少的。

更新:我不确定Acrobat 8​​用于导出表单数据的工具(在表单|管理表单数据|导出数据|另存为类型:XML下)是否与您在Reader中使用的功能完全相同,但是对其进行简单观察行为是,如果在导出数据功能时,字段为空,则导出的XML中不包含XML标记。这与表单是否已保存到磁盘无关,因为该字段已清空。因此,如果您的表单就是这种情况,那么可能的解决方法是暂时将字段的值设置为非空的,将PDF导出为XML然后再进行更改。

// Type Lib: D:\Program Files\Adobe\Acrobat 8.0\Acrobat\plug_ins\AcroForm.api (1)
// IID\LCID: {7CD06992-50AA-11D1-B8F0-00A0C9259304}\0

// *********************************************************************//
// Interface: IField
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {673E8454-7646-11D1-B90B-00A0C9259304}
// *********************************************************************//
  IField = interface(IDispatch)
    ['{673E8454-7646-11D1-B90B-00A0C9259304}']
    function  Get_Name: WideString; safecall;
    function  Get_Value: WideString; safecall;
    procedure Set_Value(const pbstrVal: WideString); safecall;
    function  Get_IsHidden: WordBool; safecall;
    procedure Set_IsHidden(pIsHidden: WordBool); safecall;
    function  Get_IsTerminal: WordBool; safecall;
    function  Get_Type_: WideString; safecall;
    function  Get_IsReadOnly: WordBool; safecall;
    procedure Set_IsReadOnly(pIsRO: WordBool); safecall;
    function  Get_IsRequired: WordBool; safecall;
    procedure Set_IsRequired(pIsReqd: WordBool); safecall;
    function  Get_PrintFlag: WordBool; safecall;
    procedure Set_PrintFlag(pIsPrint: WordBool); safecall;
    procedure SetBorderColor(const bstrColorSpace: WideString; GorRorC: Single; GorM: Single;
                             BorY: Single; K: Single); safecall;
    procedure SetBackgroundColor(const bstrColorSpace: WideString; GorRorC: Single; GorM: Single;
                                 BorY: Single; K: Single); safecall;
    function  Get_BorderWidth: Smallint; safecall;
    procedure Set_BorderWidth(pVal: Smallint); safecall;
    function  Get_Alignment: WideString; safecall;
    procedure Set_Alignment(const pVal: WideString); safecall;
    function  Get_CharLimit: Smallint; safecall;
    procedure Set_CharLimit(pVal: Smallint); safecall;
    function  Get_DefaultValue: WideString; safecall;
    procedure Set_DefaultValue(const pVal: WideString); safecall;
    function  Get_IsMultiline: WordBool; safecall;
    procedure Set_IsMultiline(pVal: WordBool); safecall;
    function  Get_IsPassword: WordBool; safecall;
    procedure Set_IsPassword(pVal: WordBool); safecall;
    procedure SetExportValues(arrExportVal: OleVariant); safecall;
    procedure SetJavaScriptAction(const bstrTrigger: WideString; const bstrTheScript: WideString); safecall;
    procedure SetSubmitFormAction(const bstrTrigger: WideString; const bstrTheURL: WideString;
                                  theFlags: Integer; arrFields: OleVariant); safecall;
    procedure SetResetFormAction(const bstrTrigger: WideString; theFlags: Integer;
                                 arrFields: OleVariant); safecall;
    procedure SetButtonIcon(const bstrFace: WideString; const bstrFullPath: WideString;
                            pageNum: Smallint); safecall;
    function  Get_CalcOrderIndex: Smallint; safecall;
    procedure Set_CalcOrderIndex(pVal: Smallint); safecall;
    function  Get_BorderStyle: WideString; safecall;
    procedure Set_BorderStyle(const pVal: WideString); safecall;
    procedure SetForegroundColor(const bstrColorSpace: WideString; GorRorC: Single; GorM: Single;
                                 BorY: Single; K: Single); safecall;
    procedure PopulateListOrComboBox(arrItems: OleVariant; arrExportVal: OleVariant); safecall;
    function  Get_Editable: WordBool; safecall;
    procedure Set_Editable(pVal: WordBool); safecall;
    function  Get_Highlight: WideString; safecall;
    procedure Set_Highlight(const pVal: WideString); safecall;
    function  Get_Style: WideString; safecall;
    procedure Set_Style(const pVal: WideString); safecall;
    function  Get_TextFont: WideString; safecall;
    procedure Set_TextFont(const pVal: WideString); safecall;
    function  Get_TextSize: Smallint; safecall;
    procedure Set_TextSize(pVal: Smallint); safecall;
    procedure SetButtonCaption(const bstrFace: WideString; const bstrCaption: WideString); safecall;
    function  Get_ButtonLayout: Smallint; safecall;
    procedure Set_ButtonLayout(pVal: Smallint); safecall;
    function  Get_NoViewFlag: WordBool; safecall;
    procedure Set_NoViewFlag(pVal: WordBool); safecall;
    property Name: WideString read Get_Name;
    property Value: WideString read Get_Value write Set_Value;
    property IsHidden: WordBool read Get_IsHidden write Set_IsHidden;
    property IsTerminal: WordBool read Get_IsTerminal;
    property Type_: WideString read Get_Type_;
    property IsReadOnly: WordBool read Get_IsReadOnly write Set_IsReadOnly;
    property IsRequired: WordBool read Get_IsRequired write Set_IsRequired;
    property PrintFlag: WordBool read Get_PrintFlag write Set_PrintFlag;
    property BorderWidth: Smallint read Get_BorderWidth write Set_BorderWidth;
    property Alignment: WideString read Get_Alignment write Set_Alignment;
    property CharLimit: Smallint read Get_CharLimit write Set_CharLimit;
    property DefaultValue: WideString read Get_DefaultValue write Set_DefaultValue;
    property IsMultiline: WordBool read Get_IsMultiline write Set_IsMultiline;
    property IsPassword: WordBool read Get_IsPassword write Set_IsPassword;
    property CalcOrderIndex: Smallint read Get_CalcOrderIndex write Set_CalcOrderIndex;
    property BorderStyle: WideString read Get_BorderStyle write Set_BorderStyle;
    property Editable: WordBool read Get_Editable write Set_Editable;
    property Highlight: WideString read Get_Highlight write Set_Highlight;
    property Style: WideString read Get_Style write Set_Style;
    property TextFont: WideString read Get_TextFont write Set_TextFont;
    property TextSize: Smallint read Get_TextSize write Set_TextSize;
    property ButtonLayout: Smallint read Get_ButtonLayout write Set_ButtonLayout;
    property NoViewFlag: WordBool read Get_NoViewFlag write Set_NoViewFlag;
  end;
© www.soinside.com 2019 - 2024. All rights reserved.