在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");,但没用。

我是编程新手。

h1>FPDI 1.x

FPDI使用文件系统函数浏览PDF文档(例如fseek())。这要求打开的流是可查找的,如果使用http包装,则不是这样。您将需要文档的本地副本,或者实现一个单独的流包装器,允许您从例如变量中读取。

FPDI 2.x

在FPDI2中,您不再需要使用流包装器,但您可以通过使用StreamReader类的实例来读取变量,该类可以像这样创建和传递:

// 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));