【发布时间】:2019-09-20 11:37:01
【问题描述】:
如何从 url 而不是本地文件夹中解析 pdf(s)?
$pageCount = $pdf->setSourceFile($local_pdf_file);
上面的代码工作正常,我可以从本地文件夹获取 pdf 并且可以将我的文本写入 pdf,但我想从远程服务器的 url 获取 pdf。我试过这个:
$remote_url = 'https://remoteserver.com/file.pdf';
$pageCount = $pdf->setSourceFile(StreamReader::createByString($remote_url));
但这不起作用,我也使用了 fopen,file_get_contents。我不能得到好的结果,我该怎么做?谢谢大家。
// get the page count
$pageCount = $pdf->setSourceFile($local_pdf_file);
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size[0] > $size[1]) {
$pdf->AddPage('L', array($size[0], $size[1]));
} else {
$pdf->AddPage('P', array($size[0], $size[1]));
}
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetFont('Helvetica');
$pdf->SetXY(5, 5);
$pdf->Write(8, 'Watermark');
}
$pdf->Output();
【问题讨论】:
-
可以从远程服务器获取pdf文件,但是不能在远程服务器上写入pdf文件。您需要在本地服务器上编写它。
-
是的,我知道,我尝试从远程服务器获取文件,并将其保存到本地临时目录然后编辑。再次上传到远程服务器后,我不能