I had the same question and here is what I did to get the PDF output.
(1) Take the "printanswers.php" file and make a copy (pa.php for example)
(2) Modify the new pa.php as below:
(3) Use
code.google.com/p/wkhtmltopdf/ to convert to PDF
Code below:
<?php
/*
* MODIFIED - NON-WORKING CODE!!! NEED TO TWEAK TO WORK!!!
*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: NEW printanswers.php 10922 2011-09-02 14:02:28Z c_schmitz $
*
*/
$surveyid = $_GET["surveyid"];
$id = $_GET["id"];
$token = $_GET["token"];
if (is_null($surveyid))
{
echo "No Survey Id Passed in URL";
//header('Location:
www.example.com/');
exit();
}
if ((is_null($id) && is_null($token)))
{
echo "Neither id nor token passed in URL";
//header('Location:
www.example.com/');
exit();
}
//Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB
require_once(dirname(__FILE__).'/classes/core/startup.php');
require_once(dirname(__FILE__).'/config-defaults.php');
require_once(dirname(__FILE__).'/common.php');
$valquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE sid=$surveyid";
$dtresult=db_execute_num($valquery);
if ($dtresult->RecordCount()==0)
{
echo "Invalid Survey id";
exit();
}
$valquery = "SELECT id,submitdate FROM ".db_table_name('survey_'.$surveyid)." WHERE ";
if (is_null($id))
$valquery .= "token='".db_quote($token)."'";
else
$valquery .= "id=$id";
$dtresult=db_execute_num($valquery);
if ($dtresult->RecordCount()==0)
{
echo "Survey Not Started or Invalid survey token / id";
exit();
}
$dtresult=db_execute_assoc($valquery);
$dtdata=$dtresult->FetchRow();
if (is_null($id))
{
$id = $dtdata;
}
if (is_null($dtdata))
{
echo "Survey Incomplete";
exit();
}
$language = GetBaseLanguageFromSurveyID($surveyid);
$clang = SetSurveyLanguage( $surveyid, $language);
// Get the survey inforamtion
$thissurvey = getSurveyInfo($surveyid,$language);
//SET THE TEMPLATE DIRECTORY
if (!isset($thissurvey) || !$thissurvey)
{
$thistpl=validate_templatedir("default");
}
else
{
$thistpl=validate_templatedir($thissurvey);
}
//if ($thissurvey=='N') die(); //Die quietly if print answers is not permitted
//CHECK IF SURVEY IS ACTIVATED AND EXISTS
$actquery = "SELECT * FROM ".db_table_name('surveys')." as a inner join ".db_table_name('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=$surveyid";
$actresult = db_execute_assoc($actquery); //Checked
$actcount = $actresult->RecordCount();
if ($actcount > 0)
{
while ($actrow = $actresult->FetchRow())
{
$surveytable = db_table_name("survey_".$actrow);
$surveyname = "{$actrow}";
}
}
//OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK.
//SHOW HEADER
//***********************************************************************
$printoutput = '';
$aFullResponseTable=aGetFullResponseTable($surveyid,$id,$language);
//Get the fieldmap @TODO: do we need to filter out some fields?
unset ($aFullResponseTable);
//unset ($aFullResponseTable);
unset ($aFullResponseTable);
unset ($aFullResponseTable);
unset ($aFullResponseTable);
//unset ($aFullResponseTable);
unset ($aFullResponseTable);
//unset Feedback Answers
$gid = $assessments;
$grpid = "gid_" . $gid;
unset ($aFullResponseTable[$grpid]);
// Below this is the rest of the original printanswers.php code
// modified to suit your needs of output
// It should mostly work as is but I customized it for my output
// by creating a new css, etc.
// The format of print is as follows
// Start with this
$printoutput1 = '';
$printoutput1 .= "<div class='printouttitle'> Output Heading here - $surveyname ?</div><p> \n";
$printoutput .= "<table class='printouttable' >\n";
// This is for heading
$printoutput .= "<tr class='printanswersgroup'><td colspan='3'>Submission core details</td></tr>\n";
// Question and Answer
// $printoutput .= "<tr class='printanswersquestionhead'><td>Item</td><td>Question here</td><td>Answer here</td></tr>\n";
// Anywhere here is some more sample that is modified from the original on the actual output:
// I CUT AND PASTED THIS FROM A WORKING CODE, BUT DID NOT TEST IT AS I REMOVED SOME SECTIONS THAT WERE VERY SPECIFIC TO MY NEEDS
// PLEASE MODIFY AND TEST BEFORE USE - USE AT OWN RISK!
//
// ALSO NOTICE I TOOK OUT THE PDF PART COMPLETELY. WHY? BECAUSE I USE
//
code.google.com/p/wkhtmltopdf/ to then take the output to PDF from HTML
// wkhtmltopdf works great!
// YOU can call this new URL directly from wkhtmltopdf - Or do a wrapper
//
foreach ($aFullResponseTable as $sFieldname=>$fname)
{
//The two lines below remove the answer codes from the answer (if any) - this is customized by me!
$ans=explode("[",$fname[2]);
$fname[2]=$ans[0];
if (substr($sFieldname,0,4)=='gid_')
{
$printoutput1 .= "</table>\n";
// This is page break between groups
$printoutput1 .= "<div style=\"page-break-before: always\"> </div>";
$printoutput1 .= "<table class='printouttable' >\n";
$printoutput1 .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
elseif (substr($sFieldname,0,4)=='qid_')
{
$printoutput1 .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
else
{
// This is customized to avoid repeating questions in dual scale
//$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
if($dfname0==$fname[0] && $dfname1==$fname[1])
{
$dfname0=' ';
$dfname1=$dfname0;
}
else
{
$dfname0=$fname[0];
$dfname1=$fname[1];
}
//$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td>{$fname[2]}</td></tr>";
$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$dfname0} {$dfname1}</td><td>{$fname[2]}</td></tr>";
$dfname0=$fname[0];
$dfname1=$fname[1];
}
}
$printoutput1 .= "</table>\n";
//Display the page with user answers
sendcacheheaders();
doHeader();
echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/startpage.pstpl'));
echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/printanswers.pstpl'),array('ANSWERTABLE'=>$printoutput1));
echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/endpage.pstpl'));
echo "</body></html>";
?>