This can be done using DataObjects. Have a look at functions such as openDataObject, setDataObjectContents and exportDataObject.
Ah, great, yes that seems to do what I want.
However, I get an error ...
My code is as follows:
// assembles text and puts it into the variable: output
output = "Hello, world";
var output = "";
Unfortunately I get this error and I don't understand it!
InvalidGetError: Get not possible, invalid or unknown.
Obviously I'm doing somethign wrong ... but what?
Thanks very much,
The problem is with something else. Post the entire code, and also specify
which version you have of Acrobat and how you are launching this code.
I can send the output to a Report (in PDF format, obviously) or to the console, but I can't see how to send it to a plain text file, which is what I need.
You can save the report as text.
OK, I have found the problem I was having.
Basically I want to find out the page number referred to by a bookmark. I only seem to be able to do this by calling Bookmark.execute() and then seeing what the current pageNum is. That's fine if the document is open. However, I am running a batch process on (eventually) several thousand documents and so I can't have them all open. The error was caused by not opening the document first, so I couldn't call execute() on a non-present bookmark.
So, I guess my question is really: how do I access the action of a bookmark? i.e. the cExpr code that is used in Bookmark.createChild() or the cScript that is set in Bookmark.setAction().
So, I guess my question is really: how do I access the action of a bookmark?
However, your point about the batch process is not clear to me. When you run
a batch process on some files, each one of those files is opened, then the
script is executed, and then the file is closed. So it should be possible to
use the execute() command from within a batch process.
That is what I would expect - that each file would be opened, code executed, then closed, but that is not what appears to happen, because Bookmark.execute() seems to have no context because the file is not open (or perhaps not fully open in the "app" context). Therefore an error is thrown.
I tried to get round this by opening each file within my code as a Doc but you aren't allowed, it seems, to have something opening behind the batch process window. "this" seems to be a Doc but not one with its full set of methods - very strange.
Anyway, in the end I have it all working nicely but I am having to open a dozen files at a time, then run my batch process on "open files" rather than something convenient like a folder, then closing all the files at the end. Not a great hardship but still, it is a small hardship!
You may search for the free command line tools PDFTK or mbtPdsAsm.
Both tools can read bookmarks and acoording pagenumbers from the filestructure.
Latter can also write bookmarks into the file.
best regards, Reinhard