Ok, I pulled my hair out for days on this one. After tireless googling every iteration of terms related to my problem I was able to find one instance of a solution that actually worked (I tried installing pdflib lite, phpinfo, ghostscript, xpdf, etc. etc., to measure dimensions to no avail). What worked was this (you need the FPDI_Protection package [free]):
$specs = $pdf->getTemplateSize($tplidx);
$pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L');
The full function is as follows:
function pdfEncrypt ($origFile, $password, $destFile) // RESPONSIBLE FOR ADDING PASSWORD PROTECTION TO PDF FILES
{
require_once('fpdi/FPDI_Protection.php');
$pdf = new FPDI_Protection();
// set the format of the destinaton file
$pdf->FPDF('P', 'in', array('8.5','11'));
//calculate the number of pages from the original document
$pagecount = $pdf->setSourceFile($origFile);
// copy all pages from the old unprotected pdf in the new one
for ($loop = 1; $loop <= $pagecount; $loop++)
{
$tplidx = $pdf->importPage($loop);
$specs = $pdf->getTemplateSize($tplidx);
$pdf->addPage($specs['h'] > $specs['w'] ? 'P' : 'L');
$pdf->useTemplate($tplidx);
}
// protect the new pdf file
$pdf->SetProtection(array('print'), $password, '');
$pdf->Output($destFile, 'F');
return $destFile;
}
The addition of those two lines of code was able to detect whether the original page was portrait of landscape, and recreate the page in the output file the same way. Hallelujah.