Forum How do I...?

How to limit the character length in the bookmark

Chella
I have to make the bookmark to display only 123 characters and ellipsis will be added after that. Is there any feature available in princexml to limit the character length of the bookmark?

Thanks & Regards,
Chella|TNQ Technologies
+91 98 84 504995

mikeday
You can do this with JavaScript, like this:
<html>
<head>
<script>
Prince.addScriptFunc("make_bookmark", function(text) {
    var MAX_LENGTH = 32;
    if (text.length > MAX_LENGTH) {
        text = text.substring(0, MAX_LENGTH) + "...";
    }
    return text;
});
</script>
<style>
h1 { bookmark-label: prince-script(make_bookmark, content()) }
</style>
</head>
<body>
<h1>This is a very very long heading that will produce a very very long
bookmark unless we use JavaScript to make it shorter.</h1>
</body>
</html>

This should produce a document where the bookmark is "This is a very very long heading..."