ai_cover_letter_generator/main.js

27 lines
880 B
JavaScript
Raw Normal View History

2025-02-11 17:00:36 -05:00
const fs = require('fs');
const pdf = require('pdf-parse');
// Path to the PDF file you want to extract text from
const pdfPath = 'data/kyle_resume.pdf';
// Function to extract text from the PDF and return it as a string
async function extractTextFromPDF(pdfPath) {
try {
const data = await fs.promises.readFile(pdfPath); // Use promises with fs
const pdfData = await pdf(data); // Parse the PDF
return pdfData.text; // Return the extracted text
} catch (error) {
throw new Error('Error extracting text from PDF: ' + error.message);
}
}
(async () => {
try {
const extractedText = await extractTextFromPDF(pdfPath); // Waits for PDF extraction to complete
// console.log('Extracted Text:', extractedText); // Logs the extracted text
} catch (error) {
console.error(error.message); // Catches and logs any errors that occurred
}
})();