These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Loop through text formatting styles

goofy78270
Registered: Dec 7 2009
Posts: 15
Answered

Within JS, is there a way to loop through all text formatting styles and create bookmarks for certain styles?

I have created a combined doc using the insert pages function with JS but seem to be missing the bookmarks.

When trying to insert bookmarks based on the structure through Acrobat-Bookmark-Options, I get all the desired bookmarks but they are all level 1 bookmarks.

I would like to loop through all formatting types and create bookmarks as follows:

level 1 - Heading 1
level 2 - Heading 2
level 3 - Heading 3
etc...

I am pretty sure a recursive loop will work, but I am unsure how to test the structure/formatting of a text section. Can someone point me in the right direction for determining the formatting attached to a pdf text section?

My Product Information:
Acrobat Pro 8.1.7, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahhh, It would have been nice to have had this info in your other thread:(

http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=23123

I had no idea this is what you wanted to do. So the answer is No there is no reasonable way to do this. Primarily because Acrobat does not contain any logical content structure. The structure in a PDF has to do with placment of graphical items on the page. The is no such thing as a paragraph or heading. Words don't even have to appear in order.

These kinds of bookmarks are added to a PDF when it is converted from it's native application. Merging two documents and maintaining the bookmarks is beyound the capabilities of Acrobat JavaScript. JavaScript cannot copy a bookmark from one document to another because the bookmark destinations only make sense in thier own document.

To do this you need more sophisticated merge and bookmark tools. Both www.artspdf.com and www.evermap.com make tools that might help with this.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

goofy78270
Registered: Dec 7 2009
Posts: 15
Is there a way to compare a position within a source a document (.doc or .xls) and a pdf document?

To explain further, if I skip to the bookmark within the source document, can I corespond that to the same position within the pdf? If not, is there a way to read in a line at a time and create the bookmark at that time?

Given that Javascript is the scripting language for Acrobat, it seems kind of limiting. Do you happen to know if scripting through C/C++ will allow the looping through formatting types? This has to be possible somehow as Acrobat as this information stored within the document as shown by the create bookmarks via structure option.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
At the most basic level a PDF only contains the info necessary to place graphical items on the page. However, this idea of maintaining logical structure has always been around and a few versions ago Adobe added in a way to markup the grapical content with structure tags. Whether or not this information is actually in the PDF, and how good it is, depends on the software that converted the original file into a PDF. The Acrobat conversion from a Doc file is pretty good.

Accessing and making sense of this structure info is not an easy task. It is not availible to the JavaScript model. Scripting in Acrobat is primarily concerned with interactive document features and automating the kinds of tasks that the user would do from the Acrobat UI. Acrobat is not a content editing program, so there is no real connection between the JavaScript model and anything that has to do with content on the PDF.

You're only option to access content and any structure info is to write your own Acrobat plug-in using the Acrobat SDK. And yes, this is done in C++. To do this you will need a very good working knowledge of the internal PDF strucure. You can find all kinds of info on the www.adobe.com/devnet/acrobat site, and this is where you can download the SDK.

There are also 3rd party PDF parsing and building libaries such as iText and QuickPDF. And many more. If your into it you can roll your own converter. But this is not a trival task. It's an epic quest.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script