parseFile($filePath); $text = $pdf->getText(); // Split text into lines and return the first 10 lines $lines = explode("\n", $text); return array_slice($lines, 0, 10); // Get first 10 lines } // Function to create an image from text function createImageFromText($textLines, $outputPath) { $im = new Imagick(); $draw = new ImagickDraw(); $draw->setFontSize(20); $draw->setFillColor('black'); // Create a blank canvas $im->newImage(800, 600, new ImagickPixel('white')); // Write each line of text to the image $y = 40; // Starting position foreach ($textLines as $line) { $draw->annotation(10, $y, $line); $y += 30; // Move down for the next line } // Set image format and save $im->setImageFormat('jpg'); $im->drawImage($draw); $im->writeImage($outputPath); $im->clear(); $im->destroy(); } // Main script if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['fileToUpload'])) { $uploadDir = 'uploads/'; $uploadFile = $uploadDir . basename($_FILES['fileToUpload']['name']); // Move uploaded file to the uploads directory if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadFile)) { // Extract text from the PDF $textLines = extractTextFromPdf($uploadFile); // Create an image from the extracted text $outputImagePath = 'output/image.jpg'; createImageFromText($textLines, $outputImagePath); echo "Image created successfully: View Image"; } else { echo "File upload error."; } } ?>
Select PDF to upload: