Hello,
Background ::
I am writing a web app in C# / ASP.NET and I'm using the Acrobat COM object. Through that COM object I am able to get an instance of JSObject which theoretically should allow me to call anything in Acrobat's Javascript library.
I am trying to invoke the saveAs method in order to save the file as XML and it isn't working.
Now I have read several posts here in the forums and checked the documentation. I now know that the saveAs function can only be called in a Console Event or a Batch Event due to security reasons.
I have also seen posts on creating a trusted function that is able to execute with elevated permissions.
So I have two questions.
Questions ::
1) Can anyone provide me with a link to a tutorial or an explanation of how to add custom scripts to Adobe? Do I just put them in the Acrobat\JavaScripts folder?
2) Assuming I have a custom script that is set to run the saveAs at elevated permissions, is this script available to be run through the Acrobat COM object? Will I be able to access my custom trusted function through the JSObject I can retrieve through the Acrobat COM object in a C# / ASP.NET application?
Sample Code (For anyone that may be interested in seeing it. I copied a lot of the code from the C# examples that came with the Adobe SDK)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acrobat;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string document = @"C:\tags.pdf";
AcroAVDoc g_AVDoc = null;
g_AVDoc = new AcroAVDoc();
g_AVDoc.Open(document, "");
if (document != null && g_AVDoc.IsValid())
{
CAcroPDDoc pdDoc;
Object jsAcroObj;
try
{
pdDoc = (CAcroPDDoc)g_AVDoc.GetPDDoc();
jsAcroObj = pdDoc.GetJSObject();
Type T = jsAcroObj.GetType();
object[] arguments = new object[] { "C:\\Temp\\test.xml", "com.adobe.Acrobat.xml-1-00" };
T.InvokeMember("saveAs", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance,
null, jsAcroObj, arguments);
}
catch (Exception ex)
{
var error = ex.Message;
}
}
}
}
}
The answer was that I should have put the custom script into the User's script folder not the Applications script folder.
I was successful in calling the user script and saving the pdf document to XML through my custom script.