setSourceFile($tmpPath);
// Import each page and add it to the new PDF
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$size = $pdf->getTemplateSize($templateId);
$pdf->AddPage($size[‘orientation’], [$size[‘width’], $size[‘height’]]);
$pdf->useTemplate($templateId);
}
// Output the new PDF to a temporary file
$unprotectedPdfPath = tempnam(sys_get_temp_dir(), ‘unprotected’) . ‘.pdf’;
$pdf->Output($unprotectedPdfPath, ‘F’);
// Serve the file for download
header(‘Content-Type: application/pdf’);
header(‘Content-Disposition: attachment; filename=”unprotected.pdf”‘);
readfile($unprotectedPdfPath);
// Clean up temporary files
unlink($unprotectedPdfPath);
exit;
} catch (PdfParserException $e) {
die(‘Error processing PDF: ‘ . $e->getMessage());
}
}
?>
Upload and Remove PDF Password