Ask a Question related to Adobe Acrobat SDK, Design and Development.
-
holmesd@adobeforums.com #1
How to access bookmarks using C#
Hi,
I'm trying to access the list of bookmarks in a PDF. I've written my application in C#, and I'm having trouble figuring out how to access this part of a PDF document.
From reading the documentation, this forum, and a few other sources - my understanding is that the collection of bookmarks may only be access using C++, or JavaScript. (I'd love to be proven wrong here though...)
If I want to access the bookmarks from within my C# app, it seems that the advice is to use the JSObject from within my app.
I've seen a few examples around for VB, and lots for VBS, but I can't get them to work for C#.
Basically, as far as I get is:
AcroAVDoc acroAVDoc = new AcroAVDoc();
acroAVDoc.Open(inputFile, "");
CAcroPDDoc acroDoc = (CAcroPDDoc)acroAVDoc.GetPDDoc();
Object jsObj = pdDoc.GetJSObject();
This is where I get stuck. I don't know how to call into the javascript library from here. Looking at a few examples for VB, the answer seems to be something like:
bookMarkRoot = jsObj.BookmarkRoot
But that won't compile for C#. (Neither will bookMarkRoot = jsObj.BookmarkRoot();)
What am I missing here?
Thanks in advance for the help.
holmesd@adobeforums.com Guest
-
Bookmarks
Where do I locate the IE bookmarks in system X? and what do they call them in that file? Thanks -
asp.net and bookmarks
I need to be able to add bookmarks programmatically via an asp.net web page. Is it feasible? If so, what would be the best way? I am new to Adobe... -
PDF to PDF & bookmarks
We are creating big pdf files from framemaker. 1st printfiles in high resolution. Then we need the same pdf files in low resolution. Both pdf... -
Bookmarks in 6 are bad!
I have made many pdf's with Acrobat version 5, and I commonly use bookmarks that are just single digits (ie: 1 2 3 ...). When I open these pdf's in... -
Bookmarks?
I created a website that works great. However, I have a page that I would like to include bookmarks so that users can select an item from a table... -
PDL@adobeforums.com #2
Re: How to access bookmarks using C#
But that won't compile for C#.
Yup. Because the JSObject is late-bound in C# you need to use the InvokeMember helper method.
PDL@adobeforums.com Guest
-
holmesd@adobeforums.com #3
Re: How to access bookmarks using C#
Thanks PDL. That was tremendously helpful.
I have two more related questions now.
First, is there anyway to execute the javascript without opening a new Acrobat window? (The code I have forces Acrobat to load.)
Second, I think I'm still missing something when calling the javascript.
I now have:
AcroAVDoc acroAVDoc = new AcroAVDoc();
acroAVDoc.Open(inputFile, "");
CAcroPDDoc acroDoc = (CAcroPDDoc)acroAVDoc.GetPDDoc();
Object jsObj = pdDoc.GetJSObject();
object[] param = new object[1];
param[0] = "";
object ret =
JsObj.GetType().InvokeMember("this.bookmarkRoot.ch ildren[0]",
System.Reflection.BindingFlags.InvokeMethod, null, jsObj,param);
However, this returns an unknown member exception (or something similar). I'm fairly certain that I should be able to call bookmarkRoot.children[0]. I suspect that I'm not correctly referencing the document though. I've tried this.bookmarkRoot, my.bookmarkRoot, doc.bookmarkRoot and just bookmartRoot, but none of them are found. Is there some other way to get a handle on the default pdf?
Thanks again in advance.
(Aandi, your suggestion is probably perfectly valid, but if I did that, I would be using COM, C#, VB and Javascript in a single app... perhaps a bit much for me. :) )
holmesd@adobeforums.com Guest
-
PDL@adobeforums.com #4
Re: How to access bookmarks using C#
You need to use just "bookmarkRoot.children[0]", but you're using the InvokeMethod binding flag - this is not a method, it is a property, so use the GetProperty binding flag instead.
Here is a list of the available binding flags:
<http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx>
PDL@adobeforums.com Guest
-
PDL@adobeforums.com #5
Re: How to access bookmarks using C#
You may want to simplify things by making use of document-level functions. Write your JS in a document-level function like:
function GetFirstBookmark( oDoc )
{
return oDoc.bookmarkRoot.children[0];
}
Then you can call this from your C#:
object[] param = new object[1];
param[0] = jsObj; // This is your JavaScript Doc object
object ret =
jsObj.GetType().InvokeMember("GetFirstBookmark",
System.Reflection.BindingFlags.InvokeMethod, null, jsObj,param);
PDL@adobeforums.com Guest
-
Aandi_Inston@adobeforums.com #6
Re: How to access bookmarks using C#
The JavaScript interface is for VB. You might want to create a VB
application as a bridge.
Aandi Inston
Aandi_Inston@adobeforums.com Guest
-
Reinhard_Franke@adobeforums.com #7
Re: How to access bookmarks using C#
...... jsObj.GetType().InvokeMember("GetFirstBookmark", ....
That may become very cumbersome if you have a nested bm-tree.
(Is that correct english?)
I would check if you can use: ExecuteThisJavaScript (in Acroabt FORMS reference).
Then you can write the AJS-code "dump all bookmarks" (in JS-Helpfile) to a C# variable and execute the AJS-code. Read the AJS variable for the bm-tree via jso into C# and do whatever you want with that.
HTH, Reinhard
Reinhard_Franke@adobeforums.com Guest
-
PDL@adobeforums.com #8
Re: How to access bookmarks using C#
(Is that correct english?)
Yup! :)
I was only providing the "GetFirstBookmark" function as an example. My intent was for them to have all the JS in document-level functions, then just invoke those functions as necessary. Much less cumbersome than doing the whole thing through either InvokeMember or ExecuteThisJavaScript.
PDL@adobeforums.com Guest
-
holmesd@adobeforums.com #9
Re: How to access bookmarks using C#
Huzzah!!!
It took me a while to figure out how to actually return a value back to the C# app. Getting a method to run was really easy, but actually getting a value back from a property took me a bit. I ended up with the following code.
AcroAVDoc acroAVDoc = new AcroAVDoc();
acroAVDoc.Open(inputFile, "");
CAcroPDDoc acroDoc = (CAcroPDDoc)acroAVDoc.GetPDDoc();
// Create a IAFormApp object. Required in order to create
// a Fields object.
IAFormApp formApp = new AFormAppClass();
// Get the IFields object associated with the form
IFields acrofields = (IFields)formApp.Fields;
// Values are returned to the app through the event. You
// must assign the return value to event.value in order
// to get something other than a null value.
String ret = acrofields.ExecuteThisJavascript(
"event.value = this.bookmarkRoot.children[0].name;");
Console.Out.WriteLine("Bookmark: " + ret.ToString());
acroAVDoc.Close(0);
Thanks PDL, Reinhard.
holmesd@adobeforums.com Guest
-
Unregistered #10
How to access bookmarks using C#
What are the references needed to use iField?
Unregistered Guest



Reply With Quote

