Forums

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.

Thanks
Rahul
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.

Bob
ozneilau 02 Nov, 2010
I have had some success creating a PDF by using the free FPDF library at: http://www.fpdf.org

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).

Neil.

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

<?php
require('libraries/fpdf/fpdf.php');

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

//Add Logo
$pdf->Image('images/stories/logo.jpg',57,38,42,24);

//Add Box
$pdf->SetLineWidth(0.2);
$pdf->Rect(9,9,92,55,'D');

//Add Address
$pdf->SetXY(11,11);
$pdf->SetFont('Helvetica','',7);
$pdf->MultiCell(35,3,"\nyour_title_here\nyour_phone_no_here\nyour_address_here",0,'L');

//Add Other Text including variables from Database
$pdf->SetXY(10,28);
$pdf->SetFont('Helvetica','B',9);
$pdf->Cell(25,4,'Name:',0,0);
$pdf->SetFont('Helvetica','',9);
$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();
$dir='tmp/';
$h = opendir($dir);
while($file=readdir($h))
  {
  if(substr($file,0,3)=='tmp' && substr($file,-4)=='.pdf')
    {
    $path = $dir.$file;
    if($t-filemtime($path)>3600)
    @unlink($path);
    }
  }
closedir($h);
?>
GreyHead 06 Nov, 2010
Hi Neil,

Very useful, thank you.

Bob
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:

<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>


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.

Bob
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.