在 FPDF 中设置 pdf 路径

Setting pdf path in FPDF

我正在尝试从

设置pdf路径
$pageCount = $pdf->setSourceFile("doc.pdf");

(doc.pdfphp 脚本位于同一目录中)

上传到其他服务器上的 pdf (http://www.example.com/xyz.pdf)

我试过这个:$pageCount = $pdf->setSourceFile("http://www.example.com/xyz.pdf");但是没用。

我是编程新手。帮助将不胜感激

FPDI 1.x

FPDI 使用文件系统函数在 PDF 文档中导航(例如 fseek()). This requires that the stream that is opened is seekable which isn't the case if an http wrapper is used. You will need a local copy of the document or implement an individual stream wrapper that would allow you to read from e.g. a variable

FPDI 2.x

在 FPDI 2 中,您不再需要使用流包装器,但您可以使用 StreamReader class 的实例从变量中读取,它可以像这样创建和传递这个:

// use a resource
$fh = fopen('a/path/to/a.pdf', 'rb');
$pdf->setSourceFile(new StreamReader($fh));
// same as
$pdf->setSourceFile($fh);
// don't forget to call fclose($fh);

// use a path
$path = 'a/path/to/a.pdf';
$pdf->setSourceFile(StreamReader::createByFile($path));
// same as
$pdf->setSourceFile($path);

// use a string
$pdfString = '%%PDF-1.4...';
$pdf->setSourceFile(StreamReader::createByString($pdfString));