I'm working with C#, and Adobe Acrobat 6.0 Professional. Acrobat exposes a COM Automation server with a few top-level objects. It's easy enough to create instances of those objects, by getting their Type via the .GetTypeFromProgID() method, and then using Activator.CreateInstance().

// Create an Acrobat Application object
Type AcrobatAppType;
AcrobatAppType = Type.GetTypeFromProgID("AcroExch.App");
Acrobat.CAcroApp oAdobeApp = (Acrobat.CAcroApp)Activator.CreateInstance(AcrobatAppType);

// Create an Acrobat Document object;
Type AcrobatPDDocType;
AcrobatPDDocType = Type.GetTypeFromProgID("AcroExch.PDDoc");
Acrobat.CAcroPDDoc oAdobePDDoc = (Acrobat.CAcroPDDoc)Activator.CreateInstance(AcrobatPDDocType);

// Create an Acrobat AV Document object;
Type AcrobatAvType;
AcrobatAvType = Type.GetTypeFromProgID("AcroExch.AVDoc");
Acrobat.CAcroAVDoc oAdobeAVDoc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatAvType);

However, there are other objects that can only be created by calling a method of one of these top-level objects. For example, Acrobat's built-in JavaScript engine can be returned via the "GetJSObject()" method of the PDDoc object.

This code, for example, compiles and runs:

object oAcrobatJSobj = oAdobePDDoc.GetJSObject();

However, since this object isn't strongly typed, it isn't really useful. I can't call any of its inherent methods or properties.

How can you type and instantiate such an object?

Recommended Answers

All 3 Replies

I ran into the same issue dealing with the Acrobat JSObject. How I solved it was by creating a separate VB.Net project within my current C# solution used specifically for accessing the JSObject. The class I built is below:

Public Class PDFConverter
Private m_PDFApp As Acrobat.AcroApp
Private m_PDDoc As Acrobat.AcroPDDoc
Private m_AVDoc As Acrobat.CAcroAVDoc
Private m_JSOjb As System.Object
#End Region

Public Function ConvertToTIFF(ByVal FilePath As String, ByVal ImagePath As String) As Boolean
m_PDFApp = New Acrobat.AcroApp ' CreateObject("AcroExch.App")
m_PDDoc = New Acrobat.AcroPDDoc ' CreateObject("AcroExch.PDDoc")

m_AVDoc = m_PDDoc.OpenAVDoc("temp")


m_JSOjb = m_PDDoc.GetJSObject()

m_JSOjb.SaveAs(ImagePath, "com.adobe.acrobat.tiff")
End Function
#End Region
End Class

And this is how I call it.

PDFToTiffConverter.PDFConverter conv = new PDFToTiffConverter.PDFConverter();
conv.ConvertToTIFF(CurrentFilePath, m_strCachePath);

Hopefully this helps.

-- tecshack

Although this thread was already been few years long let me share my solution by using Reflection. For example to access the SaveAs(...) method with 2 parameters of destination and image format we can do this in C# by:

// Create the JavaScript object
object jsObj = oAdobePDDoc.GetJSObject();

// Create Tiff file
	object[] saveAsParam = { "C:\\destination.tif", "com.adobe.acrobat.tiff" };
	Type T = jsObj.GetType();
	T.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, jsObj, saveAsParam );

Hopefully this would be useful to someone who wants to develop all the code in C# instead of making additional library in VB.Net.


Legend! I could kiss you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.