Page 1 of 1

Problem with FPDF showing date correctly

PostPosted: Tue Jul 07, 2009 8:00 am
by tomhousley
I have succesfully created action etc to use FPDF to create pdfs from content in my database.

However, I'm not able to get it to print dates correctly.

Here is print_this_action.php

The
Code: Select all
import('actions/pdf.php');
is another php file I use for the headers & footers.


Code: Select all
<?php
define('FPDF_FONTPATH','actions/font/');
require('actions/fpdf.php');
import('actions/pdf.php');
class dataface_actions_print_this_action {
function handle(&$params){
$app =& Dataface_Application::getInstance();
$record =& $app->getRecord();

$pdf_body = $record->val('cor_body');
$pdf_date = $record->val('cor_date');

$pdf=new PDF();

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('arial','',10);
$pdf->SetLeftMargin(20);
$pdf->SetRightMargin(20);

$pdf->Cell(190,4,'',0,1,'L',0);
$pdf->Ln(20);

$pdf->Cell(10,20,$pdf_date,0,1,'L',0);

$pdf->Ln(20);

$pdf->MultiCell(0,5,$pdf_body,0,1);
$pdf->Output();
}
}
?>


The $pdf_body prints fine. the $pdf_date shows up in the PDF as just the word Array.

Any help would be greatly appreciated.

Many thanks, Tom

PostPosted: Tue Jul 07, 2009 1:05 pm
by shannah
You should use the strval() method of Dataface_Record rather than val(). Some types of data are stored internally as arrays or objects. In particular date fields are stored as arrays. Using strval() ensures that you will get the string version.

-Steve

formatting date in FPDF

PostPosted: Tue Jul 07, 2009 2:24 pm
by tomhousley
Thank you Steve,

One more question... how do i format the date, currently it looks like:

2009-07-16 21:13:00

... I would like something like:

16 July 2009

Can't get my head round how the date thing in PHP works in this.

Currently have:

Code: Select all
$pdf_dmy = $record->strval('cor_date');


Code: Select all
$pdf->Cell(165,5,$pdf_dmy,0,1,'R',0);


Thank you for your help, Tom.

PostPosted: Tue Jul 07, 2009 3:06 pm
by shannah
See http://ca.php.net/manual/en/function.date.php
for date formatting options:

You would do something like:
Code: Select all
date('Y-m-d', strtotime($record->strval('mydatefield')));


-Steve

Re: Problem with FPDF showing date correctly

PostPosted: Tue Jun 26, 2012 10:55 pm
by shannah
You can't write HTML directly into a PDF. I think that libraries like FPDF may support limited HTML styling of text in certain structures (e.g. Multicell), but certainly not full HTML.

If you want to layout your PDF using HTML and CSS, you may want to look at a library like dompdf instead.

-Steve

Re: Problem with FPDF showing date correctly

PostPosted: Wed Jun 27, 2012 12:08 am
by cookie720
tcpdf has a write html function TCPDF::writeHTML which supports li div, and even img.....but im getting an error
Code: Select all
TCPDF ERROR: [Image] Unable to get image: http://localhost/live_matters/xataface/images/document_icon.gif

Re: Problem with FPDF showing date correctly

PostPosted: Wed Jun 27, 2012 1:29 pm
by shannah
Is that URL working?

Re: Problem with FPDF showing date correctly

PostPosted: Wed Jun 27, 2012 5:30 pm
by cookie720
yeah it is! but im not even sure why it would need that image, i was trying to display a BLOB field