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

How to import XMP file to a PDF?

Bonurbe
Registered: Mar 3 2008
Posts: 10

Hi,

I've read the tutorial of Thom Parker creating a button and importing the same metadata into a PDF and thought it was a great idea. The problem is that in my case the metadata are different for every PDF created. I've also created my own custom panel in the "additional metadata" window of Acrobat.

I'm hence wondering if the following would work. Import the customed XMP file into a PDF by using a button?

Thanks,
Bonurbe.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Unfortunately you cannot import a custom XMP file directly into a PDF. But there is a round about way that it can be done from a JavaScript toolbar button.

For example, for an all JavaScript solution you could write a script that loads the XMP file into an embedded file, using the "doc.importDataObject()" function, and then use the XMLData object to parse and insert the custom XMP into the document metadata. There is an example of using the XMLData object in the doc.metadata entry in the Acrobat JavaScript Reference.

Another approach that might be more suitable for you purpose is to use the Acrobat IAC interface to build a VB application that passes the custom XMP data into an Acrobat Folder Level Script that then parses and inserts the custom XMP into the document metadata.

You can find both the Acrobat JavaScript Reference and the IAC reference on this site:

http://www.adobe.com/devnet/acrobat/

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

Bonurbe
Registered: Mar 3 2008
Posts: 10
Thanks Thom,

that's what I wanted to know.

Cheers,
Bonurbe.
Tuffy_Ven
Registered: Jun 29 2008
Posts: 68
We are also trying the same.

Can any one please give little info on XML parse ie parsing and insertion of XMP file.

Thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Look in the Acrobat 8 JavaScript API Reference at the "App.metadata" object. One of the examples provides a very large script for parsing the XMP metadata and adding new info into it.

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

Tuffy_Ven
Registered: Jun 29 2008
Posts: 68
Thomp Great Thanks for help.
david_343
Registered: Jan 7 2009
Posts: 8
Hi,

How import metadata(contains special characters) in acrobat batch processing using javascript. pls see below my code.

this.importDataObject("XMP_File", xmpFle);
var xmpFile = this.getDataObjectContents("XMP_File");
var xmp_contents = util.stringFromStream(xmpFile,"utf-8");
app.alert(xmp_contents);

using the above code the accent(special) characters are not getting inserted.

any one can help me.

thanks in advance
david_343
Registered: Jan 7 2009
Posts: 8
Hi,

this.importDataObject("XMP_File", xmpFle);
var xmpFile = this.getDataObjectContents("XMP_File");
var xmp_contents = util.stringFromStream(xmpFile,"utf-8");
app.alert(xmp_contents);

using the above code the accent(special) characters are not getting inserted in acrobat metadata.

any one can help me.

thanks in advance
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you are using non-Latin characters, then you should be storing the data in the attached file as "utf-16".

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]

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

david_343
Registered: Jan 7 2009
Posts: 8
Hi

I am using spanish characters, even if i use utf-16/utf-8, i am not able to insert accent characters in the pdf metadata.

pls help me
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Wow, this is really interesting. I tried a test using your code, where the XML file that was Attached to the PDF contained all ANSI (8-bit) characters, with some acented characters. ANSI characters are also the first set of 256 characters in Unicode.

The "this.getDataObjectContents()" function faithfully returned all the characters in the file, no problems here. It's the "util.stringFromStream()" function that failed. It completely ignored any characters that were not strictly in the English Character set. Just for kicks I also tried the other character decodings and they all failed to convert the acented characters correctly. Which is interesting because since they are in ANSI they really don't need any conversion. JavaScript is Unicode based.

So the "util.stringFromStream()" fucntion is either buggy, broken, or just weak. This conclusion is further supported by my next experiment.

Next I converted the XML file into UTF-16. Note, I converted the data in the file to UTF-16. This worked, all the acented characters were maintianed in Acrobat when I used "stringFromStream" with the "utf-16" decoding. But it's not as clean as you would like. The "stringFromStream" function doesn't seem to recognize the standard UTF-16 byte ordering tag. So in order for it to work, the XML has to be Big Endian with no prefix for byte ordering.

There is another alternative for you. Write your own conversion routine for the ANSI (utf-8) characters, instead of using "util.stringFromStream". This is actually quite simple.

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]

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

david_343
Registered: Jan 7 2009
Posts: 8
Hi Thom,

Still i am getting the same.

For e.g I try to insert below title into pdf metadata using javascript in batchprocessing, actually this title is present in one xmp file

Fibrosis quística en adultos: acuerdos inter e intraobservador para las escalas de puntuación de Brasfield y Chrispin-Norman en la radiografía de tórax y relación con datos clínicos y espirométricosafter using this sctipt

this.importDataObject("XMP_File", "/c/xmp/test.xmp");
var xmpFile = this.getDataObjectContents("XMP_File");
var xmp_contents = util.stringFromStream(xmpFile, "utf-8");
console.println(xmp_contents)


the title changed as below, all accent(special) characters(í , ó) are missing.

Fibrosis qustica en adultos: acuerdos inter e intraobservador para las escalas de puntuacin de Brasfield y Chrispin-Norman en la radiografa de trax y relacin con datos clnicos y espiromtricoscould you pls give some solution to insert accent character(í , ó)

Thanks in advance for you help

David
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I would suggest converting the "/c/xmp/test.xmp" file to UTF-16 characters. This can be done with any reasonably sophisticated XML tool, like XML Spy. You can download a free trial. Then, in your code, change "utf-8" to "utf-16" in the "util.stringFromStream()" function.

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]

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

david_343
Registered: Jan 7 2009
Posts: 8
Hi thomp

when i changed "utf-8" to "utf-16" in the "util.stringFromStream()" function, the out put displaying as follows

㰿硰慣步琠扥杩渽∿∠楤㴢圵䴰䵰䍥桩䡺牥卺乔捺正㥤∿㸼砺硭灭整愠硭汮猺砽≡摯扥㩮猺浥瑡⼢⁸㩸浰瑫㴢䅤潢攠塍倠䍯牥‴⸰ⵣ㌱㘠㐴⸲㔳㤲ㄬ⁓畮⁏捴‰ㄠ㈰〶‱㜺ㄴ㨳㤢㸼牤昺剄䘠硭汮猺牤映㴠≨瑴瀺⼯睷眮眳⹯牧⼱㤹㤯〲⼲㈭牤昭獹湴慸⵮猣∠硭汮猺灤晸‽•桴瑰㨯⽮献慤潢攮捯洯灤晸⼱⸳⼢⁸浬湳㩰摦慩搠㴠≨瑴瀺⼯睷眮慩業⹯牧⽰摦愯湳⽩搯∠硭汮猺硡瀠㴠≨瑴瀺⼯湳⹡摯扥⹣潭⽸慰⼱⸰⼢⁸浬湳㩸慰剩杨瑳‽•桴瑰㨯⽮献慤潢攮捯洯硡瀯ㄮ〯物杨瑳⼢⁸浬湳㩤挠㴠≨瑴瀺⼯灵牬⹯牧⽤振敬敭敮瑳⼱⸱⼢⁸浬湳㩤捴敲浳‽•桴瑰㨯⽰畲氮潲术摣⽴敲浳⼢⁸浬湳㩰物獭‽•桴瑰㨯⽰物獭獴慮摡牤⹯牧

david
steev43230
Registered: Nov 21 2010
Posts: 5
Could someone help me out on this - point out what I'm doing wrong? Why is it "undefined"?


Acrobat JavaScript Debugger Functions Version 7.0
Acrobat Database Connectivity Built-in Functions Version 7.0
Acrobat EScript Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Functions Version 7.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 7.0
Acrobat Multimedia Version 7.0
Acrobat SOAP 7.0

this.importDataObject("XMP_File", "/C/Program Files/Adobe/Acrobat 7.0/Acrobat/JavaScripts/GLCopyright.xmp");
var xmpFile = this.getDataObjectContents("XMP_File");
var xmp_contents = util.stringFromStream(xmpFile,"utf-8");
app.alert(xmp_contents);
ReferenceError: xmp_contents is not defined
1:Console:Exec
undefined


What I'm trying to do is write a javascript that will import some "Additional Metadata." I created the metadata on the Additional Metadata page and then exported the file, and then tried to reimport manually and that works fine. Now I want a js action attached to a toolbar button that will do that for me. Since 7.0 is so much easier to use, I'm trying to get the script working in 7.0.

I can enter

this.importDataObject("XMP_File", "/C/Program Files/Adobe/Acrobat 7.0/Acrobat/JavaScripts

at the console and when I do I get a return of "true" but no metadata is imported.

===Update===
I never could get the code to work at the console. I did get it to work via custom button but while it would import the file, it did not update the metadata.

Custom button code that worked (Acrobat 7 Pro):
var SetMetaData = app.trustedFunction(function()
{
app.beginPriv();
this.importDataObject("cName", "/C/Program Files/Adobe/Acrobat 7.0/Acrobat/JavaScripts/GLC.xmp");
app.endPriv();
});

app.addToolButton({
cName: "applyMetaData",
cLabel: "GLC",
cEnable: "event.rc = (app.doc != null);",
cExec: "SetMetaData();"});
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Your code (after the update) does nothing more than to import a new data object (in the form of a file attachment) to the file.
This by itself can not update the metadata of the file.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com