Hi
I have found this http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/wwhelp/wwhim pl/js/html/wwhelp.htm?href=JS_Dev_Overview.71.1.html#1515775&accessib l e=true
in the Acrobat 9 documentation. However this does not work. I tried this in an annotation-script:
| var a = new Resource("pdf://test.jpg"); | |
| var myImage = new Image( a ); | |
console.println("myImage="+myImage); |
As you can see, it is almost to the letter what is given in the example. There is no error-message. The consoleout this produces is the following:
myImage=Image: "pdf://test.jpg" (0x0 pixels, 0 colors)
It will work provided the file you're using as a resource is embedded into the RMA and is readable. It sounds in this case that the format of your JPEG isn't correct.
Here's a quick utility function to drop into your RMA so you can test via the console:
function loadDiffTex(_materialName, _resourceName) {
var _mat = scene.materials.getByName(_materialName);
var _res = new Resource("pdf://" + _resourceName);
host.console.println("Resource created, type= " + _res.type);
var _tex = new Image( _res );
host.console.println("Image object created: " + _tex.toString());
_mat.diffuseTexture.image = _tex
}
If your 3D scene has a material in it called 'mat1' and you've attached a JPEG called 'test.jpg' then run the console commands
getAnnots3D(pageNum)[0].context3D.loadDiffTex('mat1','test.jpg');
and see what it says. Note that the filename reported by the Image object may be corrupted, that's a bug in the 3D API but it doesn't stop things working.
That's about exactly how my function looks. ^^ In fact it does work using .png-images. When using any of the embedded jpgs I get an error exactly where the actual swapping occurrs, as the image-object created from the resource is empty except for its name. The exact error is this:
newTexture=Image: "pdf://test.jpg" (0x0 pixels, 0 colors)
Line: 31: Code: 45(0x2d): Object is invalid
GeneralError: Vorgang fehlgeschlagen.
ScriptProxy.(null):1:Doc undefined:Exec
Line: 31: Code: 45(0x2d): Object is invalid
// "Vorgang fehlgeschlagen" would be something like "Procedure failed" in english.
The jpgs are embedded and named correctly, and were created in PhotoshopCS4, based on renderings from Blender. They are ordinary jpgs, 1024x1024 px at ~200KB in size. I saved them the usual way (I tried every compression-setting PS gives me: baseline/standart, baseline/optimized and progressive). Each one of them opens up without any problem in every software I have installed that can open jpgs (that includes Acrobat 9 pro Extended). I even tried to strip all exif-data from the files, but didn't get them to work.
Are there any other specifications for jpgs to use in texture-swapping that I'm not aware of?
I see. So the problem was that jpg-images have to be saved without ICC-profile (for colormanagement), which is enabled by default when saving from Photoshop. Just unticking the option will make the jpgs useable as ressources in a 3D-annotation.
You can see the finished PDF here, if anyone is interested:
North America
Europe, Middle East and Africa
Asia Pacific