Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am using Drupal version 7.18 and have installed TCPDF package in my library under /var/www/html/drupal-sites/all/libraries

Everything is working well for my generated pdf report.

However, when i open /var/log/php.log on my server, i found errors which was generated everytime i click to generate the PDF report on my site:

PHP Fatal error: Cannot use object of type REPORT_PDF as array in /var/www/html/drupal-7.18/includes/form.inc on line 799

I am not sure what is happening. It has flooded my log file.

REPORT_PDF was an object in the function:

$pdf = new REPORT_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

NEW INFO AFTER CHANGING hook_menu() TO REMOVE drupal_get_form():

PHP Fatal error: Cannot use object of type REPORT_PDF as array in /var/www/html/drupal-7.18/modules/block/block.module on line 269

I am not sure what is happening. It has flooded my log file.

In my .module file:

$items['report/download/nih_pdf/%'] = array(
  'title' => NIH PDF',
  'page callback' => 'nih_pdf',
  'page arguments' => array(3),
  'file' => 'staffreport_pdf.inc',
  'access callback' => 'nih_login_access',
);

and in my .inc file:

function nih_pdf($arg1) {

if (!class_exists('TCPDF')) {

include_once(libraries_get_path('tcpdf') . '/tcpdf.php');
}

$pdf = new REPORT_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('FP System');
$pdf->SetTitle('NIH Report');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array('freesans', '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array('freesans', '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$pdf->SetFont('freesans', '', 10);

$pdf->AddPage();
$pdf->setPrintHeader(false);

$txt = <<

//HTML data displayed as string

EOD;
$pdf->writeHTML($txt, true, false, false, false, '');

ob_end_clean();
//Close and output PDF document
$pdf->Output($staff_num.'_NIH.pdf', 'D');

$pdf->Close();

return $pdf;
}

class REPORT_PDF extends TCPDF {

//Page header
public function Header() {
$this->SetY(15); //use in place of logo
$this->SetFont('freesans', 'B', 16);
$this->Cell(0, 15, 'NIH REPORT', 0, false, 'C', 0, '', 0, false, 'M', 'M');
}

// Page footer
public function Footer() {
$this->SetY(-15);
$this->SetFont('freesans', 'I', 8);
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}

Hope somebody can assist. Thanks!

share|improve this question
Re: your comment "REPORT_PDF" was an object," that's apparently quite true because the error message is saying that some form expects it to be an array, eg, the message "cannot use object...as [an] array," so I'd look into any custom forms you may have and see where you are be passing $pdf and it is expecting an array, not an object. Once you find that, casting it to an array should fix things up. – Jimajamma May 6 at 2:55
any idea how can i turn off this error from logging in my log file or how do i fix my codes? My pdf function is actually stored in an INC file in one of my own developed modules, im not sure why does it concern the form.inc it is mentioning..Thanks – esiaz May 6 at 3:13
I had formed all my html codes inside a $txt string and use $pdf->writeHTML($txt, true, false, false, false, ''); to write into the pdf. – esiaz May 6 at 3:16
well, something obviously is getting the forms system involved albeit errantly. check in your module as well as the library for any functions that might accidently follow the forms naming structure. quick guess is something in there is named form_HOOK something or other without knowing it will be called by drupal. – Jimajamma May 6 at 12:23
i realise i am using 'page callback' => 'drupal_get_form', 'page arguments' => array('nih_pdf'), as i need to pass in the id to retrieve the appropriate report pdf, my function is function nih_pdf($form, &$form_state) {...} is there any other way i can use so i can retrieve the id and pass it into my pdf function without using form or? my url is someting like xxx.xxx.xx/portal/stafflist/nih_pdf/10109_APT-CV.pdf. Thanks – esiaz May 7 at 1:18
show 8 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.