Problem with FPDF showing date correctly

A place for users and developers of the Xataface to discuss and receive support.

Problem with FPDF showing date correctly

Postby tomhousley » Tue Jul 07, 2009 8:00 am

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
tomhousley
 
Posts: 52
Joined: Thu Feb 26, 2009 1:02 am
Location: United Kingdom

Postby shannah » Tue Jul 07, 2009 1:05 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

formatting date in FPDF

Postby tomhousley » Tue Jul 07, 2009 2:24 pm

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.
tomhousley
 
Posts: 52
Joined: Thu Feb 26, 2009 1:02 am
Location: United Kingdom

Postby shannah » Tue Jul 07, 2009 3:06 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Problem with FPDF showing date correctly

Postby shannah » Tue Jun 26, 2012 10:55 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Problem with FPDF showing date correctly

Postby cookie720 » Wed Jun 27, 2012 12:08 am

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
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: Problem with FPDF showing date correctly

Postby shannah » Wed Jun 27, 2012 1:29 pm

Is that URL working?
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Problem with FPDF showing date correctly

Postby cookie720 » Wed Jun 27, 2012 5:30 pm

yeah it is! but im not even sure why it would need that image, i was trying to display a BLOB field
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 15 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved