我正在使用FPDF()方法(来自FPDI_Protection.php)导入现有的PDF并应用密码保护。FPDF - 它能处理混合方向(纵向/横向)的原始PDF吗?
我遇到的问题是,原始PDF混合了纵向和横向页面(8.5“X11”& 11“X8.5”),而导入方法使您可以定义一次。我可以将新创建的pdf定义为11“X11”,它可以修复其中一个方向裁剪的问题,但这对于打印目的并不理想,因为PDF会缩放并左对齐,从而导致可读性/打印输出较差。
有没有什么样的例程可以使用,因为原始文档正在循环检测原始大小并设置新的页面方向?
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, in our case 6×9 inch
$pdf->FPDF('P', 'in', array('11','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);
$pdf->addPage();
$pdf->useTemplate($tplidx);
}
// protect the new pdf file, and allow no printing, copy etc and leave only reading allowed
$pdf->SetProtection(array('print'), $password, '');
$pdf->Output($destFile, 'F');
return $destFile;
}
,或者,有没有添加密码来使用PHP现有的PDF更简单的方法?
我想尝试的一件事是对TCPDF运行稍微修改后的代码。它是由同一个人写的,但定期更新。 – mkaatman 2013-03-05 23:19:48
@mkaatman - 我对这个建议非常失望。在我看来,TCPDF要求你在构建时定义一个单一的大小,就像这样。 – 2013-03-06 07:00:55
我希望进口会更优雅。 – mkaatman 2013-03-06 15:12:26