Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Delphi中集成Adobe SDK以编辑PDF_Delphi_Pdf_Pdf Generation_Delphi Xe5_Pdf Form - Fatal编程技术网

在Delphi中集成Adobe SDK以编辑PDF

在Delphi中集成Adobe SDK以编辑PDF,delphi,pdf,pdf-generation,delphi-xe5,pdf-form,Delphi,Pdf,Pdf Generation,Delphi Xe5,Pdf Form,我正在开发一个应用程序,在这个应用程序中,我需要能够编辑现有的PDF表单,并以交互方式在文件上删除PDF表单字段 表单字段,如下拉、文本、多行文本、单选按钮。目前我正在使用ActiveX控件在Delphi应用程序中打开PDF文件 不过,我只能阅读PDF表单,但我希望能够像删除表单字段一样对其进行编辑 其想法是在现有PDF表单上添加表单并保存它。 我尝试过Gnostice、PowerPDF、quickPDF,但它们不允许像ADOBE那样以交互方式修改PDF文件。 这个在线应用程序允许我们以交互方式

我正在开发一个应用程序,在这个应用程序中,我需要能够编辑现有的PDF表单,并以交互方式在文件上删除PDF表单字段

表单字段,如下拉、文本、多行文本、单选按钮。目前我正在使用ActiveX控件在Delphi应用程序中打开PDF文件

不过,我只能阅读PDF表单,但我希望能够像删除表单字段一样对其进行编辑

其想法是在现有PDF表单上添加表单并保存它。 我尝试过Gnostice、PowerPDF、quickPDF,但它们不允许像ADOBE那样以交互方式修改PDF文件。 这个在线应用程序允许我们以交互方式创建新的和编辑现有的PDF表单

在Gnostic中,我们可以通过编程方式进行编辑,如:

问题:

  • 是否有一种方法可以交互编辑PDF表单以删除表单字段
  • 我们可以在Delphi中嵌入Adobe或任何其他软件来编辑现有的PDF吗

Acrobat的完整版本包括从Delphi代码访问和操作表单字段的功能,并支持将表单字段添加到文档、通过OLE自动化使用代码填充表单字段以及在不需要时删除表单字段等操作

您当然可以在自己的应用程序中设置Acrobat窗口,以便在TPanel中显示f.i。您可以使用Acrobat_TLB.Pas中CAcroAVDoc对象的
OpenInWindowEx
方法执行此操作。但是,这只绘制PDF文档(加上注释/注释,iirc),它不提供显示或访问Acrobat的gui。从Delphi应用程序中我知道的唯一方法是在TOleContainer对象中打开Pdf文件,但如果这样做,Acrobat的gui将在自己的窗口中打开,而不是在您的窗口中。如今,鹰嘴容器界面在屏幕上看起来确实是过时的

所以,如果您想要与Acrobat的表单字段编辑器gui交互,我想您已经被卡住了。另一方面,您可以使用自己的DIY代码操作表单字段并填充它们-请参见下面的示例

要在代码中操作表单字段,需要将Acrobat表单类型库导入Delphi。
需要导入的类型库相当于

D:\Program Files\Adobe\Acrobat 8.0\Acrobat\plug_ins\AcroForm.api 
您可能需要使用Delphi的TRegSvr实用程序(或Windows的RegSvr32)向Windows注册此文件

这使您可以访问IAFormApp对象,该对象是用于处理表单的顶级对象,以及IField对象,该对象用于创建单个字段

如果您有Acrobat SDK文档,则“应用程序间通信API参考”(iac_API_Reference.pdf)中描述了通过Ole自动化使用这些对象的方法。我在下面介绍了IFIeld界面的Delphi导入,这样您就可以看到可以使用它进行的各种操作

“是否有一种方法可以交互编辑PDF表单以删除表单字段?”

在Acrobat中打开表单后,可以删除字段(如果“删除”是指“删除”)。您可以通过调用IFields接口的
Remove
方法在代码中完成此操作

“我们能否在Delphi中嵌入Adobe或任何其他软件来编辑现有的PDF?”

是的,以下示例显示如何从Delphi代码中填写现有字段并添加新字段:

implementation

{$R *.DFM}

uses
  AFORMAUTLib_TLB, Acrobat_TLB;

const
  scDocument = 'D:\delphi\code\acrobat\blank.pdf';

procedure TForm1.FillInForm;
var
  Acrobat : CAcroApp;
  AVDoc : CAcroAVDoc;
  PDDoc : CAcroPDDoc;
  FormApp : IAFormApp;
  Fields : IFields;
  Field : IField;
begin
  Acrobat := CoAcroApp.Create;
  AVDoc := CoAcroAVDoc.Create;
  AVDoc.Open(scDocument, scDocument);
  PDDoc := AVDoc.GetPDDoc as CAcroPDDoc;

  FormApp := CoAFormApp.Create;

  Fields := FormApp.Fields as IFields;
  Field := Fields.Item['Text1'] as IField;
  Field.Value := 'My test';

  Field := Fields.Add('AnotherField', 'text',
  0,
  360,
  790,
  360 + 200,
  790 - 30) as IField;

  Field.Value := 'Added';
end;
顺便说一句,我不确定你是否打算问这个问题,但也可以在Delphi应用程序的窗口中托管Acrobat的gui。但是如果你想知道这一点,你需要在单独的q中询问,因为这是一个不同的技术问题

摘自AFORMAUTLib_TLB.Pas:

*********************************************************************//
    // Interface: IField
    // Flags:     (4416) Dual OleAutomation Dispatchable
    // GUID:      {673E8454-7646-11D1-B90B-00A0C9259304}
    // *********************************************************************//
      IField = interface(IDispatch)
        ['{673E8454-7646-11D1-B90B-00A0C9259304}']
        // getters amd setters omitted
        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;
        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;
        procedure SetForegroundColor(const bstrColorSpace: WideString; GorRorC: Single; GorM: Single; 
                                     BorY: Single; K: Single); safecall;
        procedure PopulateListOrComboBox(arrItems: OleVariant; arrExportVal: OleVariant); safecall;
        procedure SetButtonCaption(const bstrFace: WideString; const bstrCaption: WideString); 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;

你没有接受这个答案,也没有对这个答案做出反应,这让我想知道你的问题中是否有我没有回答的方面。有吗?你是怎么做杂技演员的?我找不到它的类型库或ActiveX组件。提前谢谢。在IDE中,转到项目|导入类型库和导入Acrobar的类型库。对于v.8,它应该位于C:\Program Files(x86)\Adobe\Acrobat 8.0\Acrobat\Acrobat.tlb。这将生成.Pas导入单元,然后您可以在项目中使用它。注意:要做到这一点,您需要Acrobat的完整(付费)版本,而不仅仅是阅读器。好的,谢谢!我只有Acrobat Reader,所以这对我不起作用。我是否只需要开发者计算机上的Acrobat完整版本,还是需要所有设备上的Acrobat完整版本?标准版够了吗?还是我需要Acrobat Professional?