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

Error in BookMarkRoot.createChild? (unicode)

yipchunyu
Registered: Apr 30 2009
Posts: 8

I found some script regarding merging pdfs from below url
http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=139

it works well except one issue.
When I need to create bookmark with Chinese text (e.g. 測試TESTING), the bookmark can only been seen in the acrobat 5.0. When I tried to open the file in other version's reader e.g. 8.0. All the bookmark become strange characters. I searched the web but still can't a concrete answer for this.
Would u pls help provde any advice to me? (or this issue is known bug for the "BookMarkRoot.createChild"?
You advice should be very helpful.
Look forward to hear from you.
Yu
yipchunyu [at] gmail [dot] com

My Product Information:
Acrobat Standard 5.x or older, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In Acrobat JavaScript, unicode characters are inserted into a string with the "\u" escape sequence. Where the unicode is in Hexidecimal. So to insert your string into the first bookmark use this this code

bookmarkRoot.children[0].name = "\u6e2c\u8a66TESTING"

I tried this in Reader 8 and it works. You might want to take a look at this article
http://www.acrobatusers.com/tutorials/2006/using_unicode_text

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

yipchunyu
Registered: Apr 30 2009
Posts: 8
Dear Thomp,
Thx for your reply.
It's doesn't works yet but your answers at least give me some hopes (i tried to solve this for hours but still can't make it works).

I am using vb script and don't know whether it's the problem or not.
anyway, i got some things need to confirm:

1. file encoding of the bookmark
I stores the bookmarks in another text file and use below script to read the file
set BookMarkList = fs.OpenTextFile("C:\bkmks_chi.txt")
What encoding should I choose (as if I stores Chinese).
ANSI, Unicode, Unicode big endian, UTF-8 (from notepad)

2. Unicode strings
I checked your pdf but can't find the unicode strings for Chinese (traditional). Any help?

3. Basic question.
Does it works for VBS? Or must I change it to javascript?

Look forward to hear from you. Thx in advance.
yipchunyu
Registered: Apr 30 2009
Posts: 8
I did some other tests today and got some progress (while still not working yet).

1. the file format should use UTF-8. And I found that the OpenTextFile is not working well with unicode and i should use Adodb.Stream

2. I use reader 8.0 with the pdf file. it works now

3. I guess it will works with VBS but still can't make it yet. I created some logic with Hex and AscW. It can now read the text and convert it to unicode string like below. However, when I use BookMarkRoot.createChild BookMarkToAdd. It will make the bookmark just like the input texts (instead of translate it back to chinese characters).
Any help?

\u66F4\u7F8E\u597D
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Sounds like you are making progress. Congradulations!!

The trick to adding unicode strings to a PDF element, bookmark or text field, is to make sure everything is escaped properly. I imagine that this is the problem you are seeing. If the actual unicode character codes are being displayed, instead of the characters, then there is a problem with how the strings are escaped.

To help with this issue you should create a Folder level JavaScript function that creates the bookmarks and adds the labels. Then call this function from your VB app. This will avoid any data type translation problems between the VB and the Acrobat environments.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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

yipchunyu
Registered: Apr 30 2009
Posts: 8
thomp,
I tried again and again but no major progress. Really need your advice as the deadline to complete this task is coming soon.
What I did
1. Create a js file under C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Javascripts\BookMark.js
and create function
function BookMark1(sName, iPage)
{
// Add a bookmark
var sPage = "";

sPage = "pageNum=" & iPage;
bookmarkRoot.createChild(sName, sPage);
return 1;
}
2. change the vbscript
change from
oJSO.BookMarkRoot.createChild BookMarkToAdd, "pageNum="&LastPageOut&";",
to
vReturn = oJSO.BookMark1(BookMarkToAdd, LastPageOut)

where the BookMarkToAdd should be sth like "\u66F4\u7F8E\u597D"

but it's not working, anything goes wrong?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You need to do some debug. Please read the article on the Console Window. The link is at the bottom of my signature block.

The first thing you need to do is to test your folder level function from the Console Window. You need to know that it works first in Acrobat before using it from a VB script.

You do have one obvious error. In JavaScript strings are concatonated with the "+", not the "&".Testing in the console will clear all these issues up.

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.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

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