生成PDF时获取错误值0错误

时间:2014-04-18 16:55:43

标签: php pdf pdflib

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

'处理参数或'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();

1 个答案:

答案 0 :(得分:2)

  

'处理参数或类型'页面'的选项价值不好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和#34;异常处理"详细介绍。