Im running below code and get the error:
Code Error
Unterminated regular expression (23:95)
import { axios } from "@pipedream/platform";
import PDFDocument from "pdfkit";
import fs from "fs";
export default defineComponent({
async run({ steps, $ }) {
// Assuming you have a step named `download_file` that downloads a PDF to /tmp
const filePath = `/tmp/your-pdf-file.pdf`; // Replace with your actual file path
// Function to extract data from the PDF file
async function extractData(filePath) {
// Read the PDF content
const pdfContent = await fs.promises.readFile(filePath);
// Create a PDFKit document to parse the content
const doc = new PDFDocument();
doc.parse(pdfContent);
// Extract the date from the header (assuming format YYYY-MM-DD)
const date = doc.text().match(/(\d{4}-\d{2}-\d{2})/)[1];
// Extract names and kolli-IDs using a regular expression
const namesAndKolliIds = doc.text().match(/Inlämning Kolli-ID\/inl.nr: (.**?)(?:\n|$)/**g*/);
// Create an object to store the extracted data
const data = {
date,
namesAndKolliIds,
};
// Return the extracted data object
return data;
}
try {
const extractedData = await extractData(filePath);
console.log("Extracted data:", extractedData); // Log the extracted data for testing
// Use the extractedData object (date, namesAndKolliIds) in your Pipedream workflow