PowerPDF API - What do do when C# dynamic fails
See the question and my original answer on StackOverflowI can't test with PowerPDF that I don't have but I faced the same issue with the Adobe's Acrobat SDK itself (I guess this PowerPDF uses Acrobat SDK undercovers).
Anyway, in the Acrobat case, the C# dynamic
"pseudo-type" doesn't work because the underlying object implementing COM Automation IDispatch always fails (and actually causes a crash in Acrobat process...) when we call GetTypeInfo, which is what dynamic
does in its implementation.
The solution is to use what we did before dynamic
existed: use direct Reflection techniques like this (you may have to adapt it slightly to PowerPDF):
static void Main()
{
Type GetPDFType = Type.GetTypeFromProgID("AcroExch.PDDoc");
dynamic dvOpenDoc = Activator.CreateInstance(GetPDFType);
dvOpenDoc.Open(@"C:\TestFiles\SampleFormSource.pdf");
object jso = dvOpenDoc.GetJSObject(); // note I use object type here, not dynamic!
// these reflection calls are equivalent to jso.app.alert("Show this alert");
// get the "app" property
var app = jso.GetType().InvokeMember("app", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public, null, jso, null);
// call the "alert" method (has 1 argument)
app.GetType().InvokeMember("alert", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, app, new[] { "Show this alert" });
return;
}