Thread View: adobe.scripting.indesign
5 messages
5 total messages
Started by Thomas_B._Nielsen
Mon, 19 Jan 2009 09:35
Extract indesign preview
Author: Thomas_B._Nielsen
Date: Mon, 19 Jan 2009 09:35
Date: Mon, 19 Jan 2009 09:35
5 lines
865 bytes
865 bytes
Is it possible to get/extract the preview file saved in Indesign documents by scripting?
We are exporting a JPG file of every document, but for large format documents / complex documents til is a slow process. So i thought, perhaps it is possible to use the file that indesign saves ("Preferences -> File handling")?
Any ideas?
Re: Extract indesign preview
Author: Thomas_B._Nielsen
Date: Mon, 19 Jan 2009 13:57
Date: Mon, 19 Jan 2009 13:57
6 lines
807 bytes
807 bytes
The XMPdata under xmpGImg is base64 encoded, see this post:
<http://www.adobeforums.com/webx?128@@.3bbcb337>
Now i need to extract the data from the XMPdata("file info -> advanced tab").
How is this done?
Re: Extract indesign preview
Author: Thomas_B._Nielsen
Date: Mon, 19 Jan 2009 16:35
Date: Mon, 19 Jan 2009 16:35
11 lines
1225 bytes
1225 bytes
var myString = myDocument.metadataPreferences.getProperty("http://ns.adobe.com/xap/1.0/","Thumbnails/*[1]/xmpGImg:image");
// replace - <http://www.adobeforums.com/webx?128@@.3bbcb337>
myString = myString.replace("
", "\n");
will extract the base64 encoded data.
using the script <http://www.webtoolkit.info/javascript-base64.html> i thought i could decode the preview and then save to a file, but i get a invalid JPEG file.
However, feeding the script on the folowing url with the encoded string, forcing download, will produce a valid jpeg.
<http://opinionatedgeek.com/dotnet/tools/Base64Decode/Default.aspx>
Re: Extract indesign preview
Author: Peter Kahrel
Date: Mon, 19 Jan 2009 17:35
Date: Mon, 19 Jan 2009 17:35
90 lines
3406 bytes
3406 bytes
JavaScript implementations of Base64 decoders can be found on the web. Below is a script that uses Thomas's method to retrieve the thumbnail from the active document and a script I found (and slightly adapted) on Stephen Ostermiller's site (Google's first hit using "base64 decoder javascript").
Peter
/*The Base 64 decoder is from Stephen Ostermiller's site:
<http://ostermiller.org/calc/encode.html>
Preview extractor from Thomas Nielsen
* /
file_name = '/d/thumb.jpg';
var END_OF_INPUT = -1;
var base64Chars = new Array(
'A','B','C','D','E','F','G','H',
'I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X',
'Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v',
'w','x','y','z','0','1','2','3',
'4','5','6','7','8','9','+','/'
);
var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
reverseBase64Chars[base64Chars[i]] = i;
}
function decodeBase64(str){
setBase64Str(str);
var result = "";
var inBuffer = new Array(4);
var done = false;
while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
&& (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
inBuffer[2] = readReverseBase64();
inBuffer[3] = readReverseBase64();
result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
if (inBuffer[2] != END_OF_INPUT){
result += ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
if (inBuffer[3] != END_OF_INPUT){
result += ntos((((inBuffer[2] << 6) & 0xff) | inBuffer[3]));
} else {
done = true;
}
} else {
done = true;
}
}
return result;
}
function setBase64Str(str){
base64Str = str;
base64Count = 0;
}
function readReverseBase64(){
if (!base64Str) return END_OF_INPUT;
while (true){
if (base64Count >= base64Str.length) return END_OF_INPUT;
var nextCharacter = base64Str.charAt(base64Count);
base64Count++;
if (reverseBase64Chars[nextCharacter]){
return reverseBase64Chars[nextCharacter];
}
if (nextCharacter == 'A') return 0;
}
return END_OF_INPUT;
}
function ntos(n){
n=n.toString(16);
if (n.length == 1) n="0"+n;
n="%"+n;
return unescape(n);
}
var myString = app.activeDocument.metadataPreferences.getProperty("http://ns.adobe.com/xap/1.0/","Thumbnails/*[1]/xmpGImg:image");
myString = myString.replace("
", "\n");
jpeg_string = decodeBase64 (myString);
jpeg_file = new File (file_name);
jpeg_file.encoding = 'binary';
jpeg_file.open ('w');
jpeg_file.write (jpeg_string);
jpeg_file.close();
Re: Extract indesign preview
Author: Thomas_B._Nielsen
Date: Mon, 19 Jan 2009 17:53
Date: Mon, 19 Jan 2009 17:53
7 lines
922 bytes
922 bytes
THANK YOU :D Once more you saved the day Peter, I have tried and tried, but I guess the converter i used just wasn't working (Did try different ones, but not the one you have used, which i did not find). Perhaps something else was wrong, but now it works. I'm a very happy man now, hate to give up on an idea. /Thomas
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads