1

生成代码时出现以下错误:

''page' 类型的句柄参数或选项的值错误为 0'

这似乎是唯一的问题,但我不知道我哪里出错了。任何人都可以在这里看到问题吗?

    {
    $qty = '1000';   

//Open page once
    $indoc = $p->open_pdi_document(APPLICATION_PATH.'/../library/pdfs/fc/FCMONARCHCKS_b.pdf', "");
    $page = $p->open_pdi_page($indoc, 1, "");
    $width = $p->pcos_get_number($indoc, "pages[0]/width");
    $height = $p->pcos_get_number($indoc, "pages[0]/height");
// Looping thru the start Numbers
    for ($i = $qty; $i >= 0; $i--) {
       if($i == $qty){
          $newNo1 = $this->orderData->check_number + $qty;
      }
      else
      {
       $newNo1 = $newNo1 - 1;
   }



        //Add page that was only opened once
   $p->begin_page_ext($width, $height, "");
   $p->fit_pdi_page($page,0,0,""); 



   $checkNumber_micr = $newNo1;  

   if(strlen($checkNumber_micr) == '3') {
    $newNumber = "00000".$checkNumber_micr;
} elseif(strlen($checkNumber_micr) == '4') {
    $newNumber = "0000".$checkNumber_micr;
} elseif(strlen($checkNumber_micr) == '5') {
    $newNumber = "000".$checkNumber_micr;
} elseif(strlen($checkNumber_micr) == '6') {
    $newNumber = "00".$checkNumber_micr;
} elseif(strlen($checkNumber_micr) == '7') {
    $newNumber = "0".$checkNumber_micr;
}

$check_number ="C".$newNumber."C";
$helper->addTextBlock('check_number_1', $check_number);


$CN1 = $newNumber;
$helper->addTextBlock('CN1', $CN1);

$CN2 = $newNumber;
$helper->addTextBlock('CN2', $CN2);

$CN3 = $newNumber;
$helper->addTextBlock('CN3', $CN3);



$rep ="A121000248A";
$routing_number_1p = $rep;
$helper->addTextBlock('routing_number_1', $routing_number_1p);



$rep2 = "C 4124521923C";
$bank_number_1p = $rep2;
$helper->addTextBlock('bank_account_1', $bank_number_1p);

$p->end_page_ext("");

    }
$p->close_pdi_page($inpage);
}

//Close Page Manually not using helper
$p->end_document("");
$p->close_pdi_document($indoc);
$p->delete();
4

1 回答 1

3

''page' 类型的句柄参数或选项的值错误为 0'

这是一个后续错误。您的 open_pdi_document() 失败,但您没有检查返回值。它返回 0(错误),它不是一个有效的句柄,因此 open_pdi_page() 失败。要解决您的问题,请检查 API 调用的返回值,它返回一个句柄

$indoc = $p->open_pdi_document(APPLICATION_PATH.'/../library/pdfs/fc/FCMONARCHCKS_b.pdf', "");
if ($indoc == 0){
   throw new Exception("Error: " . $p->get_errmsg());
}
$page = $p->open_pdi_page($indoc, 1, "");
if ($page == 0){
   throw new Exception("Error: " . $p->get_errmsg());
}

(另请参阅 PDFlib 示例,它们包含在 PDFlib 包的 bind/php 目录中)

在调试过程中,还可以设置“errorpolicy=exception”。详细介绍请参见 PDFlib 9.0.2 教程,第 3.1.1 章“异常处理”。

于 2014-04-22T11:29:41.880 回答