October 22, 2024
Chicago 12, Melborne City, USA
javascript

exiftool-vendored: `extractBinaryTagToBuffer` Fails Unexpectedly


I want to read XMP data from PDFs in JavaScript:

const { exiftool } = require('exiftool-vendored');
const fs = require('fs');

async function extractXMPData(filename) {
    try {
        const buffer = await exiftool.extractBinaryTagToBuffer('XMP', filename);
        console.log(buffer.toString());
    } catch (error) {
        console.error('Error reading XMP data:', error);
    }

    // Close the exiftool instance to free resources
    await exiftool.end();
}

const filename = process.argv[2];
extractXMPData(filename);

That fails with "Error reading XMP data: Error: XMP not found".

If I extract the XMP data on the command-line with exiftool -b -XMP /path/to/file.pdf, the XMP data is extracted. Also when I write the data to a file with JavaScript:

await exiftool.extractBinaryTag('XMP', filename, 'out.xpacket');

Is this a bug in exiftool-vendored or am I doing something wrong?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video