script.tstype Option = {
extension: 'ppm' | 'pbm' | 'pgm' | 'png' | 'jpeg' | 'tiff';
verbose?: boolean;
};
export async function convertPDFtoImage(pdfFileName: string, outputName: string, {extension, verbose}: Option = {extension: 'png'}) {
if (verbose) console.log(`Converting ${pdfFileName} to ${extension} images...`);
let flag: string | undefined;
switch (extension) {
case 'ppm':
flag = undefined;
break;
case 'pbm':
flag = 'mono';
break;
case 'pgm':
flag = 'gray';
break;
default:
flag = extension;
break;
}
await exec(`pdftoppm${flag ? ` -${flag}` : ''} ${pdfFileName} ${outputName} -r ${dpi}`);
if (verbose) console.log(`Finish.`);
}