Convert to Word document

rahulngupta 21 Sep, 2009
First of all thank you very much for your replies.

I have 2 questions currently.
1. Is there a way for Chronoforms to automatically create a word/pdf document based on some selected fields entered in the form
2. Also the format of the email I send to user depends on an option he selects in the form.
For example if he chooses options 1, the format of the email will be Field A , field B, field C
for option 2 it will be Field B, Field C, Field A

This should be a rather simple php code but I am not able to get this to work. Please help me out here.

GreyHead 21 Sep, 2009
Hi rahul,

1) Not easily. It is possible to create a PDF - the way I have done it is to create an article from my form input and print that to PDF which is not idea. I have a feeling that someone posted a better solution here but I'm not certain.

2) The email is easier; probably the simplest way is to setup both emails in the Email Setup + template, disable both, then enable the one that you want to use in the OnSubmit Before box. You may need to change the run order of the email to get this to work correctly.

ozneilau 02 Nov, 2010
I have had some success creating a PDF by using the free FPDF library at:

I downloaded the file and extracted and copied the fpdf.css and fpdf.php files and the font folder up to new folder /libraries/fpdf

At first, the result was a blank screen so I followed the instructions in the FAQ on how to create the file in a temporary folder and then it worked fine (successfully tested in all the main browsers).


My code is like this (abbreviated so it's more concise):


//Create PDF
$pdf=new FPDF('P','mm','A4');

//Add Logo

//Add Box

//Add Address

//Add Other Text including variables from Database
$pdf->Cell(65,4,$MyRow->Firstname . ' ' . $MyRow->Surname,0,1);

// etc.
// etc.

//Save PDF to temporary file in /tmp folder
$file = basename(tempnam('.', 'tmp'));
rename($file, $file.'.pdf');
$file .= '.pdf';
$file = 'tmp/' . $file;
$pdf->Output($file, 'F');
header('Location: '.$file);

//Delete temporary PDF files in /tmp folder over an hour old
$t = time();
$h = opendir($dir);
  if(substr($file,0,3)=='tmp' && substr($file,-4)=='.pdf')
    $path = $dir.$file;
GreyHead 06 Nov, 2010
Hi Neil,

Very useful, thank you.

AntonioGraca 31 May, 2013
Hi, ozneilau
I'm trying to integrate fpdf with CF and is not working. Gives error.
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp 	�Z*�[����(hx����+����(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.7) /CreationDate (D:20130531100330) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 8 0000000000 65535 f 0000000228 00000 n 0000000416 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000520 00000 n 0000000595 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 644 %%EOF

ozneilau how integrated FPDF with CF, where you put the code? How code called?

thank you
AntonioGraca 31 May, 2013
I begin whith a simple code:

$pdf = new FPDF();
$pdf->Cell(40,10,'Hello World!');

In a Custom Code ...
GreyHead 31 May, 2013
Hi Antonio,

I think that is working correctly. The out put looks like a PDF file output to the browser. I think that you probably need to save it and download, or set the page header so that the browser treats it as a PDF file rather than a text or HTML file.

AntonioGraca 31 May, 2013
Hello, Bob
Thanks for the reply. I will read more about browsers and PDF output ...
thank you

António Graça
This topic is locked and no more replies can be posted.