面是vb的代码:
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
bOK = AcroExchAVDoc.Open("C:\mydoc.pdf", "")
If (bOK) Then
Set AFormAut = CreateObject("AFormAut.App")
Set Fields = AFormAut.Fields
End If
Set Field = Fields.Add("Name", "text", 0, 100, 650, 450, 675)
Field.SetBorderColor "RGB", 0.7, 0.5, 0.3, 0
Field.TextSize = "12"
Field.DefaultValue = "Enter your full name here" 以上代码是vb调用Acrobat SDK的api ,往pdf文件里写一个控件(textbox).
我如何将它转成c#呢?查找了一些帮助,我只能转换一部分,代码如下:
Acrobat.CAcroAVDoc avDoc;
Acrobat.CAcroPDDoc avPDDoc;
Acrobat.CAcroAVPageView avPageView;
Acrobat.CAcroPDPage avPDPage;
System.Type AcrobatType;
AcrobatType = Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));
avDoc= (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatType);
int isOpen=avDoc.Open(@"d:\fw4.pdf","");
int nMinPage=0;
if(isOpen==-1)
{
avPDDoc=(Acrobat.CAcroPDDoc)avDoc.GetPDDoc();
avPageView=(Acrobat.CAcroAVPageView)avDoc.GetAVPageView();
avPDPage=(Acrobat.CAcroPDPage)avPageView.GetPage();
....
//剩下的怎么转呀?}特别是:我很难找到带有Field属性 及 Fields.Add()之类的方法.
(我用到了sdk的Acrobat.dll);
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
bOK = AcroExchAVDoc.Open("C:\mydoc.pdf", "")
If (bOK) Then
Set AFormAut = CreateObject("AFormAut.App")
Set Fields = AFormAut.Fields
End If
Set Field = Fields.Add("Name", "text", 0, 100, 650, 450, 675)
Field.SetBorderColor "RGB", 0.7, 0.5, 0.3, 0
Field.TextSize = "12"
Field.DefaultValue = "Enter your full name here" 以上代码是vb调用Acrobat SDK的api ,往pdf文件里写一个控件(textbox).
我如何将它转成c#呢?查找了一些帮助,我只能转换一部分,代码如下:
Acrobat.CAcroAVDoc avDoc;
Acrobat.CAcroPDDoc avPDDoc;
Acrobat.CAcroAVPageView avPageView;
Acrobat.CAcroPDPage avPDPage;
System.Type AcrobatType;
AcrobatType = Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));
avDoc= (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatType);
int isOpen=avDoc.Open(@"d:\fw4.pdf","");
int nMinPage=0;
if(isOpen==-1)
{
avPDDoc=(Acrobat.CAcroPDDoc)avDoc.GetPDDoc();
avPageView=(Acrobat.CAcroAVPageView)avDoc.GetAVPageView();
avPDPage=(Acrobat.CAcroPDPage)avPageView.GetPage();
....
//剩下的怎么转呀?}特别是:我很难找到带有Field属性 及 Fields.Add()之类的方法.
(我用到了sdk的Acrobat.dll);
Acrobat.CAcroAVDoc avDoc;
Acrobat.CAcroPDDoc avPDDoc;
System.Type AcrobatType;
AcrobatType = Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));
avDoc= (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatType);
int isOpen=avDoc.Open(@"d:\fw4.pdf","");
if(isOpen==-1)
{
avPDDoc=(Acrobat.CAcroPDDoc)avDoc.GetPDDoc();
int nMaxPage=avPDDoc.GetNumPages(); AFORMAUTLib.Fields fields;
AFORMAUTLib.Field field;
System.Type aformLib;
aformLib = Type.GetTypeFromCLSID(new System.Guid("{673E8453-7646-11D1-B90B-00A0C9259304}"));
//上面一句出错!!!!!!!!!!!!!!!!!
fields= (AFORMAUTLib.Fields)Activator.CreateInstance(aformLib);
field= (AFORMAUTLib.Field)fields.Add("Name","text",0,100,450,250,500);
field.SetBorderColor("",25,23,23,2);
field.Value="hello";
field.DefaultValue="hello";
}
报错说:COM object with CLSID {673E8453-7646-11D1-B90B-00A0C9259304} is either not valid or not registered.
但是,第一个注册却可以通过。
why? 难道是要regsvr32 ....?
1 Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));方法只能得到你引用了得DLL,如果没有引用这个DLL,是不会成功得。2 你可以用DLLImport方式来调API,或者找到dll引用进来使用……
using Acrobat;
using AFORMAUTLib;
在注册表里,查了一下guid,acrobat与aformautlib的都得到了。
现代码更新如下:且build能成功
Acrobat.CAcroAVDoc avDoc;
Acrobat.CAcroPDDoc avPDDoc;
System.Type AcrobatType;
AcrobatType = Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));
avDoc= (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatType);
int isOpen=avDoc.Open(@"d:\fw4.pdf","");
if(isOpen==-1)
{
avPDDoc=(Acrobat.CAcroPDDoc)avDoc.GetPDDoc();
int nMaxPage=avPDDoc.GetNumPages(); AFORMAUTLib.Fields fields;
AFORMAUTLib.Field field;
System.Type aformLib;
aformLib = Type.GetTypeFromCLSID(new System.Guid("{7CD069A1-50AA-11D1-B8F0-00A0C9259304}"));
fields= (AFORMAUTLib.Fields)Activator.CreateInstance(aformLib);
//???????上面一行报错:Specified cast is not valid. field= (AFORMAUTLib.Field)fields.Add("Name","text",0,100,450,250,500);
field.SetBorderColor("",25,23,23,2);
field.Value="hello";
field.DefaultValue="hello";
}build能通过,运行时,有一行报错:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.能否给点帮助??朋友们?
Acrobat.CAcroAVDoc avDoc;
System.Type AcrobatType;
AcrobatType = Type.GetTypeFromCLSID(new System.Guid("{72498821-3203-101B-B02E-04021C009402}"));
avDoc= (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatType);
int isOpen=avDoc.Open(@"d:\fw4.pdf","");
if(isOpen==-1)
{
System.Type aformLib;
AFORMAUTLib.AFormApp app;
AFORMAUTLib.Fields fields;
AFORMAUTLib.Field field;
aformLib = Type.GetTypeFromCLSID(new System.Guid("{7CD069A1-50AA-11D1-B8F0-00A0C9259304}"));
app= (AFORMAUTLib.AFormApp)Activator.CreateInstance(aformLib);
fields=(AFORMAUTLib.Fields)app.Fields;
field= (AFORMAUTLib.Field)fields.Add("Test1","text",1,10,10,50,50);
field.SetBorderColor("RGB",1,3,6,8);
field.Value="hello";
field.DefaultValue="hello";
field.BorderWidth=2;
}
build通过,执行也没有出现什么错误,
但是控件没有写到pdf文件里去,why ??
我是模拟pdf sdk的vb代码。