yakovmeister / pdf2image

A utility for converting pdf to image and base64 format.
MIT License
435 stars 141 forks source link

[Intermittent Error] Command failed: gm identify: Unable to open file (/tmp/gm4yFeyx) [Invalid argument] #215

Open kirito286 opened 1 month ago

kirito286 commented 1 month ago

Intermittent Error Message:

Error: Command failed: gm identify: Unable to open file (/tmp/gm4yFeyx) [Invalid argument].
gm identify: Request did not return an image.

Code Snippet:

const convertPDFToImages = async (
    pdfFile: Express.Multer.File
) => {
    const options = {
        density: 300,
        width: 1200,
        height: 1800,
        format: 'png',
        savePath: pdfFile.destination,
        saveFilename: pdfFile.filename.replace(/\.[^/.]+$/, ''),
    };    
    const convert = fromPath(pdfFile.path, options);

    try {
        const images = await convert.bulk(-1);
        console.log('images==>', images);
    } catch (error) {
        console.error('Error during conversion:', error);
    }
}

The issue occurs intermittently during the conversion of a PDF file to PNG images using GraphicsMagick (gm) within a Node.js environment. The error message suggests a problem with opening the temporary file (/tmp/gm4yFeyx) and indicates that the identify request did not return an image.

Environment Details:

maciejregula commented 4 weeks ago

Did you find any workaround ?