View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
07785Bug reportsImport/Exportpublic2013-09-24 14:20
Reportermfaber Assigned Toadamzammit  
PrioritynormalSeveritypartial_block 
Status closedResolutionfixed 
Product Version2.00+ 
Fixed in Version2.05 RC 
Summary07785: Matrix question corrupts PDF (queXML)-Export
Description

The attached survey contains a matrix question (3rd question in survey).
When exporting this survey in PDF (queXML)-format, the first two questions look ok in the PDF. In the matrix questions (question A3), parts of the items of this question are repeated until the page is finished (error 1).

On all of the following pages, only one question per page is shown, even if there is enough space for more (error 2).

PDF and lss attached

Steps To Reproduce

import attached lss
export using quexml-function
have a look at the PDF in the ZIP-file

TagsNo tags attached.
Attached Files
limesurvey-quexml-1.3.12.patch (50,616 bytes)   
diff --git a/application/libraries/admin/quexmlpdf.php b/application/libraries/admin/quexmlpdf.php
index d59efd3..4832ccf 100644
--- a/application/libraries/admin/quexmlpdf.php
+++ b/application/libraries/admin/quexmlpdf.php
@@ -60,7 +60,7 @@ class quexmlpdf extends pdf {
 	 * @var int  Defaults to 15.
 	 * @since 2010-09-02
 	 */
-	protected $cornerBorder = 13;
+	protected $cornerBorder = 14;
 
 	/**
 	 * The length in MM of a corner line
@@ -223,6 +223,12 @@ class quexmlpdf extends pdf {
 	 */
 	protected $skipColumnWidth = 20;
 
+	/**
+	 * The default style for the text of the questionnaire
+	 * 
+	 * @var string  Defaults to "<style>td.questionHelp {text-align:right; font-style:italic; font-size: 8pt;} td.responseText {text-align:right; margin-right:1mm;} td.responseAboveText {text-align:left;} td.responseLabel {text-align:center; font-size:8pt;} span.sectionTitle {font-size: 18pt} span.sectionDescription {font-size: 14pt}</style>". 
+	 * @since 2010-09-16
+	 */
 	protected $style;
 
 	/**
@@ -235,7 +241,7 @@ class quexmlpdf extends pdf {
 	 * @var string  Defaults to 10.5.
 	 * @since 2011-12-20
 	 */
-	protected $singleResponseHorizontalHeight = 10.5;
+	protected $singleResponseHorizontalHeight = 11;
 
 	/**
 	 * Height of the are of each single response (includes guiding lines)
@@ -302,6 +308,14 @@ class quexmlpdf extends pdf {
 	protected $singleResponseHorizontalMax = 10;
 
 	/**
+	 * Allow single choice horizontal arrays to be split over multiple pages/columns
+	 * 
+	 * @var array  Defaults to false. 
+	 * @since 2012-08-10
+	 */
+	protected $allowSplittingSingleChoiceHorizontal = true;
+
+	/**
 	 * The height of an arrow
 	 *
 	 * @var array  Defaults to 3.
@@ -334,6 +348,14 @@ class quexmlpdf extends pdf {
 	protected $textResponseHeight = 8;
 
 	/**
+	 * The height of a pre-filled response barcode
+	 * 
+	 * @var bool  Defaults to 6. 
+	 * @since 2012-06-22
+	 */
+	protected $barcodeResponseHeight = 6;
+
+	/**
 	 * The maximum number of text responses per line
 	 *
 	 * @var mixed  Defaults to 24.
@@ -400,8 +422,10 @@ class quexmlpdf extends pdf {
 	 *
 	 * @var mixed  Defaults to 145.
 	 * @since 2010-09-20
+	 * @deprecated
+	 * @see drawLongText() for the new calculation of long text box width
 	 */
-	protected $longTextResponseWidth = 145;
+	//protected $longTextResponseWidth = 145;
 
 	/**
 	 * Default number of characters to store in a long text field
@@ -411,6 +435,21 @@ class quexmlpdf extends pdf {
 	 */
 	protected $longTextStorageWidth = 1024;
 
+	/**
+	 * The number of columns to display the sections/questions in on each page
+	 * 
+	 * @var int  Defaults to 1. 
+	 * @since 2012-05-30
+	 */
+	protected $columns = 1;
+
+	/**
+	 * The width of the border between columns
+	 * 
+	 * @var int  Defaults to 1. 
+	 * @since 2012-05-31
+	 */
+	protected $columnBorder = 1;
 
 	/**
 	 * The layout of the form for importing in to queXF
@@ -469,6 +508,14 @@ class quexmlpdf extends pdf {
 	protected $boxCP = 0;
 
 	/**
+	 * Column counter pointer (current column)
+	 * 
+	 * @var mixed  Defaults to 0. 
+	 * @since 2012-05-30
+	 */
+	protected $columnCP = 0;
+
+	/**
 	 * Background colour of a question
 	 *
 	 * @var bool  Defaults to array(220,220,220).
@@ -542,6 +589,14 @@ class quexmlpdf extends pdf {
 	protected $vasLineWidth = 0.5;
 
 	/**
+	 * The width of a line for the default value
+	 * 
+	 * @var double  Defaults to 0.5. 
+	 * @since 2012-06-14
+	 */
+	protected $defaultValueLineWidth = 0.5;
+
+	/**
 	 * Height of the VAS ending lines in mm
 	 *
 	 * @var mixed  Defaults to 4.
@@ -767,6 +822,83 @@ class quexmlpdf extends pdf {
 
 
 	/**
+	 * Get the response label font sizes (normal and small)
+	 * 
+	 * @return array containing the normal font size as the first element and small as second
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function getResponseLabelFontSize()
+	{
+		return array($this->responseLabelFontSize,$this->responseLabelFontSizeSmall);
+	}
+
+	/**
+	 * Set the response label font sizes
+	 * 
+	 * @param array $sizes normal font size first then small
+	 * 
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function setResponseLabelFontSize($sizes)
+	{
+		$this->responseLabelFontSize = intval($sizes[0]);
+		$this->responseLabelFontSizeSmall = intval($sizes[1]);
+	}
+
+	/**
+	 * Get the response text font size
+	 * 
+	 * @return int The response text font size
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function getResponseTextFontSize()
+	{
+		return $this->responseTextFontSize;
+	}
+
+	/**
+	 * Set the response text font size
+	 * 
+	 * @param int $size 
+	 * 
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function setResponseTextFontSize($size)
+	{
+		$this->responseTextFontSize = intval($size);
+	}
+
+	/**
+	 * Get the style without any HTML/etc formatting
+	 * 
+	 * @return string The style without HTML or tabs
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function getStyle()
+	{
+		return strip_tags(str_replace("\t","",$this->style));
+	}
+
+	/**
+	 * Set the CSS styling of some questionnaire elements
+	 * 
+	 * @param string $style The CSS styling of some questionnire elements
+	 * 
+	 * @return none
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2013-04-10
+	 */
+	public function setStyle($style)
+	{
+		$this->style = "<style>" . $style . "</style>";
+	}
+
+	/**
 	 * Export the layout as an XML file
 	 *
 	 * @return string The XML layout in queXF Banding XML format
@@ -904,6 +1036,9 @@ class quexmlpdf extends pdf {
 
 		//set text colour
 		$this->SetTextColor($this->textColour);
+
+		//set column pointer
+		$this->columnCP = -1;
 	}
 
 	/**
@@ -960,6 +1095,21 @@ class quexmlpdf extends pdf {
 	}
 
 	/**
+	 * The X coordinate of the start of the column
+	 * 
+	 * @return int The X coordinate of the start of the current column
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2012-05-30
+	 */
+	public function getColumnX()
+	{
+		$border = 0;
+		if ($this->columnCP > 0) 
+			$border = $this->columnBorder;
+		return $this->getMainPageX() + ($this->columnCP  * ($this->getColumnWidth() + $border)) + $border;
+	}
+
+	/**
 	 * The width of the writeable page
 	 *
 	 * @return int The width of the writeable page
@@ -972,6 +1122,21 @@ class quexmlpdf extends pdf {
 	}
 
 	/**
+	 * The width of the writable column
+	 * 
+	 * @return int The width of the current column
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2012-05-30
+	 */
+	public function getColumnWidth()
+	{
+		$border = 0;
+		if ($this->columnCP > 0) 
+			$border = $this->columnBorder;
+		return ((1 / $this->columns) * $this->getMainPageWidth()) - $border;
+	}
+
+	/**
 	 * Draw a horizontal response box with possible eye guides and arrows
 	 *
 	 * @param int $x The x position of the box area (top left)
@@ -980,9 +1145,10 @@ class quexmlpdf extends pdf {
 	 * @param bool $downarrow Draw a down arrow?
 	 * @param bool $rightarrow Draw an arrow to the right?
 	 * @param bool $smallwidth Whether or not to use the small width
+	 * @param bool $filled Whether or not to have the box pre-filled
 	 *
 	 */
-	protected function drawHorizontalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $smallwidth = false)
+	protected function drawHorizontalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $smallwidth = false, $filled =false)
 	{
 		$this->SetDrawColor($this->lineColour[0]);
 		$this->SetLineWidth($this->singleResponseBoxBorder);
@@ -1015,6 +1181,15 @@ class quexmlpdf extends pdf {
 		$this->SetLineStyle(array('dash' => '0'));
 
 		$this->Rect($x + $linelength,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty);
+
+		if ($filled)
+		{
+			//draw a cross
+			$this->SetLineWidth($this->defaultValueLineWidth);
+			$this->Line($x + $linelength, $y, $x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight);
+			$this->Line($x + $linelength + $this->singleResponseBoxWidth, $y, $x + $linelength, $y + $this->singleResponseBoxHeight);
+		}
+
 		$this->setBackground('question');
 		return array($x + $linelength,$y,$x + $linelength + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding
 	}
@@ -1027,9 +1202,10 @@ class quexmlpdf extends pdf {
 	 * @param string $position What position the box is in for the eye guides
 	 * @param bool $downarrow Draw a down arrow?
 	 * @param bool $rightarrow Draw an arrow to the right?
+	 * @param bool $filled Whether or not to have the box pre-filled
 	 *
 	 */
-	protected function drawVerticalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false)
+	protected function drawVerticalResponseBox($x,$y,$position = 'only',$downarrow = false, $rightarrow = false, $filled = false)
 	{
 		$this->SetDrawColor($this->lineColour[0]);
 		$this->SetLineWidth($this->singleResponseBoxBorder);
@@ -1072,7 +1248,7 @@ class quexmlpdf extends pdf {
 
 			$this->setDefaultFont($this->skipToTextFontSize,'B');
 
-			$this->MultiCell($this->skipColumnWidth,$this->singleResponseBoxHeight,$text,0,'L',false,0,($this->getPageWidth() - $this->getMainPageX() - $this->skipColumnWidth),$y,true,0,false,true,$this->singleResponseBoxHeight,'M',true);
+			$this->MultiCell($this->skipColumnWidth,$this->singleResponseBoxHeight,$text,0,'L',false,0,(($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth),$y,true,0,false,true,$this->singleResponseBoxHeight,'M',true);
 
 			//Reset to non bold as causing problems with TCPDF HTML CSS conversion
 			$this->setDefaultFont($this->skipToTextFontSize,'');
@@ -1082,6 +1258,15 @@ class quexmlpdf extends pdf {
 		}
 
 		$this->Rect($x,$y,$this->singleResponseBoxWidth,$this->singleResponseBoxHeight,'DF',array(),$this->backgroundColourEmpty);
+
+		if ($filled)
+		{
+			//draw a cross
+			$this->SetLineWidth($this->defaultValueLineWidth);
+			$this->Line($x, $y, $x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight);
+			$this->Line($x + $this->singleResponseBoxWidth, $y, $x, $y + $this->singleResponseBoxHeight);
+		}
+
 		$this->setBackground('question');
 		return array($x,$y,$x + $this->singleResponseBoxWidth, $y + $this->singleResponseBoxHeight); //return the posistion for banding
 	}
@@ -1237,6 +1422,10 @@ class quexmlpdf extends pdf {
 						$sqtmp['text'] .= $ttmp;
 					}
 					$sqtmp['varname'] = $sq['varName'];
+
+					if (isset($sq['defaultValue'])) 
+						$sqtmp['defaultvalue'] = $sq['defaultValue'];
+
 					$rstmp['subquestions'][] = $sqtmp;
 				}
 
@@ -1244,6 +1433,10 @@ class quexmlpdf extends pdf {
 				{
 					$rtmp = array();
 					$rstmp['varname'] = $r['varName'];
+
+					if (isset($r['defaultValue'])) 
+						$rstmp['defaultvalue'] = $r['defaultValue'];
+
 					if (isset($r->fixed))
 					{
 						$rtmp['type'] = 'fixed';
@@ -1268,6 +1461,10 @@ class quexmlpdf extends pdf {
 								$oarr = array();
 								$oarr['width'] = current($c->contingentQuestion->length);
 								$oarr['text'] = current($c->contingentQuestion->text);
+
+								if (isset($c->contingentQuestion['defaultValue'])) 
+									$oarr['defaultvalue'] = $c->contingentQuestion['defaultValue'];
+	
 								$oarr['varname'] = $c->contingentQuestion['varName'];
 								$cat['other'] = $oarr;
 							}
@@ -1282,6 +1479,10 @@ class quexmlpdf extends pdf {
 							$rtmp['type'] = 'longtext';
 						else if ($format == 'number' || $format == 'numeric' || $format == 'integer')
 							$rtmp['type'] = 'number';
+						else if ($format == 'i25')
+							$rtmp['type'] = 'i25';
+						else if ($format == 'codabar')
+							$rtmp['type'] = 'codabar';
 						else
 							$rtmp['type'] = 'text';
 						$rtmp['width'] = current($r->free->length);
@@ -1324,7 +1525,7 @@ class quexmlpdf extends pdf {
 	{
 		$this->init();
 		$this->questionnaireId = intval($questionnaire['id']);
-		$this->newPage();
+		$this->newPage(true); //first page
 
 		//Draw questionnaireInfo before if exists
 		if (isset($questionnaire['infobefore']))
@@ -1406,7 +1607,7 @@ class quexmlpdf extends pdf {
 
 
 		//fill to the end of the last page
-		$this->fillPageBackground();
+		$this->fillLastPageBackground();
 	}
 
 
@@ -1420,9 +1621,9 @@ class quexmlpdf extends pdf {
 	protected function drawInfo($info)
 	{
 		$this->setBackground('question');
-		$this->writeHTMLCell($this->getMainPageWidth(), $this->questionnaireInfoMargin, $this->getMainPageX(), $this->GetY() - $this->questionBorderBottom, "<div></div>",0,1,true,true);
-		$html = "<table><tr><td width=\"" . $this->getMainPageWidth() . "mm\" class=\"questionnaireInfo\">{$info}</td><td></td></tr></table>";
-		$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $this->questionnaireInfoMargin, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, "<div></div>",0,1,true,true);
+		$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionnaireInfo\">{$info}</td><td></td></tr></table>";
+		$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 	}
 
 	/**
@@ -1454,8 +1655,8 @@ class quexmlpdf extends pdf {
 				$this->SetY($this->GetY() + $this->helpBeforeBorderTop,false); //new line
 
 			$this->setBackground('question');
-			$html = "<table><tr><td width=\"" . $this->getMainPageWidth() . "mm\" class=\"questionHelpBefore\">{$question['helptextbefore']}</td><td></td></tr></table>";
-			$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+			$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionHelpBefore\">{$question['helptextbefore']}</td><td></td></tr></table>";
+			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 
 			//Leave a border at the bottom of the Help Before text
 			if ($this->helpBeforeBorderBottom > 0) //question border
@@ -1463,7 +1664,6 @@ class quexmlpdf extends pdf {
 		}
 
 		//Question header
-        if (isset($question['text'])) $question['text'] = FlattenText($question['text']);
 		$this->drawQuestionHead($question['title'], $question['text'],$help,$specifier);
 
 		$text = "";
@@ -1505,7 +1705,12 @@ class quexmlpdf extends pdf {
 					case 'vas':
 						$this->drawMatrixVas($subquestions,$text,$response['labelleft'],$response['labelright']);
 						break;
-
+					case 'i25':
+						$this->drawMatrixBarcode($subquestions, 'I25');
+						break;		
+					case 'codabar':
+						$this->drawMatrixBarcode($subquestions, 'CODABAR');
+						break;		
 				}
 			}
 			else
@@ -1513,6 +1718,10 @@ class quexmlpdf extends pdf {
 				$response = $r['response'];
 				$type = $response['type'];
 
+				$defaultvalue = false;
+				if (isset($r['defaultvalue']))
+					$defaultvalue = $r['defaultvalue'];
+
 				if (isset($response['text']) && !empty($response['text']))
 					$rtext = $text .  $this->subQuestionTextSeparator .  $response['text'];
 				else
@@ -1524,28 +1733,34 @@ class quexmlpdf extends pdf {
 				{
 					case 'fixed':
 						if (isset($response['rotate']))
-							$this->drawSingleChoiceHorizontal($response['categories'],array(array('text' => '', 'varname' => $varname)),$rtext);
+							$this->drawSingleChoiceHorizontal($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext);
 						else
-							$this->drawSingleChoiceVertical($response['categories'],array(array('text' => '', 'varname' => $varname)),$rtext);
+							$this->drawSingleChoiceVertical($response['categories'],array(array('text' => '', 'varname' => $varname, 'defaultvalue' => $defaultvalue)),$rtext);
 						break;
 					case 'longtext':
 						$this->addBoxGroup(6,$varname,$rtext);
-						$this->drawLongText($response['width']);
+						$this->drawLongText($response['width'],$defaultvalue);
 						break;
 					case 'number':
 						$bgtype = 4;
 					case 'currency':
 					case 'text':
 						$this->addBoxGroup($bgtype,$varname,$rtext,$response['width']);
-						$this->drawText($response['text'],$response['width']);
+						$this->drawText($response['text'],$response['width'],$defaultvalue);
 						//Insert a gap here
-						$this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
+						$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
 						$this->SetY($this->GetY() + $this->subQuestionLineSpacing,false);
 						break;
 					case 'vas':
 						$this->addBoxGroup(1,$varname,$rtext,strlen($this->vasIncrements));
 						$this->drawVas("",$response['labelleft'],$response['labelright']);
 						break;
+					case 'i25':
+						$this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'I25');
+						break;		
+					case 'codabar':
+						$this->drawMatrixBarcode(array(array('text' => $rtext, 'varname' => $varname, 'defaultvalue' => $defaultvalue)),'CODABAR');
+						break;		
 
 				}
 			}
@@ -1555,8 +1770,8 @@ class quexmlpdf extends pdf {
 		if (isset($question['helptextafter']))
 		{
 			$this->setBackground('question');
-			$html = "<table><tr><td width=\"" . $this->getMainPageWidth() . "mm\" class=\"questionHelpAfter\">{$question['helptextafter']}</td><td></td></tr></table>";
-			$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+			$html = "<table><tr><td width=\"" . $this->getColumnWidth() . "mm\" class=\"questionHelpAfter\">{$question['helptextafter']}</td><td></td></tr></table>";
+			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 
 		}
 
@@ -1590,16 +1805,62 @@ class quexmlpdf extends pdf {
 			else
 				$this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text'],$width);
 
+			$defaultvalue = false;
+			if (isset($s['defaultvalue']))
+				$defaultvalue = $s['defaultvalue'];
 
+			$this->drawText($s['text'],$width,$defaultvalue);
 
-			$this->drawText($s['text'],$width);
+			$currentY = $this->GetY();
+		
+			//Insert a gap here
+			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
+			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
+		}
+	}
+
+
+	/**
+	 * Draw a barcode as a "question"
+	 * 
+	 * @param string $subquestions 
+	 * @param mixed  $type         
+	 * 
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2012-06-22
+	 */
+	protected function drawMatrixBarcode($subquestions, $type)
+	{
+		$c = count($subquestions);
+
+		for ($i = 0; $i < $c; $i++)
+		{
+			$s = $subquestions[$i];
+
+			$this->addBoxGroup(5,$s['varname'],$s['text'],strlen($s['defaultvalue']));
+
+			$x = $this->getColumnX();
+			$y = $this->GetY();
+
+			$html = "<div></div>";
+			$this->setBackground('question');
+			$this->writeHTMLCell($this->getColumnWidth(), $this->barcodeResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false);
+
+			//draw the barcode
+			$barcodeStyle = array('align' => 'R', 'border' => false, 'padding' => '0', 'bgcolor' => $this->backgroundColourQuestion, 'text' => false, 'stretch' => false);
+			$this->write1DBarcode($s['defaultvalue'], $type, $x, $y, $this->getColumnWidth() - $this->skipColumnWidth,$this->barcodeResponseHeight,'', $barcodeStyle, 'B');
+
+			//pointer should now be at the bottom right - but make the box the width of the whole column for better reading
+			$this->addBox($x,$y,$this->GetX(),$this->getColumnWidth() + $this->getColumnX());
 
 			$currentY = $this->GetY();
 
 			//Insert a gap here
-			$this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
+			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
 			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
+			
 		}
+
 	}
 
 	/**
@@ -1637,7 +1898,7 @@ class quexmlpdf extends pdf {
 			$currentY = $this->GetY();
 
 			//Insert a gap here
-			$this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
+			$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
 			$this->SetY($currentY + $this->subQuestionLineSpacing,false);
 
 			$heading = false;
@@ -1651,26 +1912,35 @@ class quexmlpdf extends pdf {
 	 * Draw a large empty box for writing in text
 	 *
 	 * @param mixed $width   The "width" of the box. This relates to the number of "lines" high
+	 * @param bool|string $defaultvalue The default text to print in the box (if any)
 	 *
 	 * @author Adam Zammit <adam.zammit@acspri.org.au>
 	 * @since  2010-09-02
 	 */
-	protected function drawLongText($width)
+	protected function drawLongText($width,$defaultvalue = false)
 	{
+		//Calculate long text box width as the width of the available column minus the skip column and question title area
+		$rwidth = $this->getColumnWidth() - $this->skipColumnWidth - $this->questionTitleWidth;
+
 		$currentY = $this->GetY();
 		$height = $width * $this->longTextResponseHeightMultiplier;
 		$html = "<div></div>";
 		$this->setBackground('question');
-		$this->writeHTMLCell($this->getMainPageWidth(), $height, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 		$this->SetY($currentY,false);
 		$this->setBackground('empty');
 		$border = array('LTRB' => array('width' => $this->textResponseBorder, 'dash' => 0));
 		//Align to skip column on right
-		$this->SetX(($this->getPageWidth() - $this->getMainPageX() - $this->skipColumnWidth - $this->longTextResponseWidth),false);
+		$this->SetX((($this->getColumnWidth() + $this->getColumnX()) - $this->skipColumnWidth - $rwidth),false);
 		//Add to pay layout
-		$this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $this->longTextResponseWidth, $this->GetY() + $height);
+		$this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $rwidth, $this->GetY() + $height);
 		$this->SetDrawColor($this->lineColour[0]);
-		$this->Cell($this->longTextResponseWidth,$height,'',$border,0,'',true,'',0,false,'T','C');
+
+		$text = "";
+		if ($defaultvalue !== false)
+			$text = $defaultvalue;
+
+		$this->Cell($rwidth,$height,$text,$border,0,'',true,'',0,false,'T','T');
 		$currentY = $currentY + $height;
 		$this->SetY($currentY,false);
 	}
@@ -1689,7 +1959,7 @@ class quexmlpdf extends pdf {
 	 */
 	protected function drawVas($text, $labelleft,$labelright,$heading = true)
 	{
-		$textwidth = $this->getMainPageWidth() - $this->skipColumnWidth - ($this->vasLength + ($this->vasLineWidth * 2.0)) - 2;
+		$textwidth = $this->getColumnWidth() - $this->skipColumnWidth - ($this->vasLength + ($this->vasLineWidth * 2.0)) - 2;
 		$this->setBackground('question');
 
 		if ($heading)
@@ -1703,7 +1973,7 @@ class quexmlpdf extends pdf {
 			$html = "<table><tr><td width=\"{$slwidth}mm\"></td><td width=\"{$lwidth}mm\" class=\"vasLabel\">$labelleft</td><td width=\"{$gapwidth}mm\"></td><td width=\"{$lwidth}mm\" class=\"vasLabel\">$labelright</td></tr></table>";
 
 
-			$this->writeHTMLCell($this->getMainPageWidth(), 0, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,false);
+			$this->writeHTMLCell($this->getColumnWidth(), 0, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false);
 		}
 
 		$currentY = $this->GetY();
@@ -1714,28 +1984,28 @@ class quexmlpdf extends pdf {
 		$textwidth += 2;
 
 
-		$this->writeHTMLCell($this->getMainPageWidth(), $this->vasAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,false);
+		$this->writeHTMLCell($this->getColumnWidth(), $this->vasAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,false);
 
 		$ncurrentY = $this->GetY();
 
 		$this->SetY($currentY,false);
-		$this->SetX($textwidth + $this->getMainPageX(),false);
+		$this->SetX($textwidth + $this->getColumnX(),false); 
 
 		$this->SetLineWidth($this->vasLineWidth);
 		$this->SetDrawColor($this->lineColour[0]);
 
 		//Draw the VAS left vert line
 		$ly = (($this->vasAreaHeight - $this->vasHeight) / 2.0) + $currentY;
-		$lx = $textwidth + $this->getMainPageX();
+		$lx = $textwidth + $this->getColumnX();
 		$this->Line($lx,$ly,$lx,$ly + $this->vasHeight);
 
 		//Right vert line
-		$lx = $textwidth + $this->getMainPageX() + $this->vasLength + $this->vasLineWidth;
+		$lx = $textwidth + $this->getColumnX() + $this->vasLength + $this->vasLineWidth;
 		$this->Line($lx,$ly,$lx,$ly + $this->vasHeight);
 
 		//Line itself
 		$ly = ($this->vasAreaHeight / 2.0) + $currentY;
-		$lx = $textwidth + $this->getMainPageX() + ($this->vasLineWidth / 2.0);
+		$lx = $textwidth + $this->getColumnX() + ($this->vasLineWidth / 2.0);
 		$this->Line($lx,$ly,$lx + $this->vasLength,$ly);
 
 		//Add to layout system
@@ -1756,14 +2026,15 @@ class quexmlpdf extends pdf {
 	 *
 	 * @param string $text The text label if any (can be HTML)
 	 * @param int $width The number of boxes to draw
+	 * @param bool|string $defaultvalue The default text to include or false if none
 	 */
-	protected function drawText($text,$width)
+	protected function drawText($text,$width,$defaultvalue = false)
 	{
 		$this->SetDrawColor($this->lineColour[0]);
 
 		//calculate text responses per line
-		$textResponsesPerLine = round(($this->getMainPageWidth() - $this->skipColumnWidth - $this->textResponseMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
-		$labelTextResponsesSameLine = round(($this->getMainPageWidth() - $this->skipColumnWidth - $this->labelTextResponsesSameLineMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
+		$textResponsesPerLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->textResponseMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
+		$labelTextResponsesSameLine = round(($this->getColumnWidth() - $this->skipColumnWidth - $this->labelTextResponsesSameLineMarginX) / ($this->textResponseWidth + $this->textResponseBorder));
 
 		//draw boxes - can draw up to $textResponsesPerLine for each line
 		$lines = ceil($width / $textResponsesPerLine);
@@ -1772,35 +2043,38 @@ class quexmlpdf extends pdf {
 		if ($width > $labelTextResponsesSameLine && !empty($text))
 		{
 			$this->setBackground('question');
-			$html = "<table><tr><td width=\"{$this->questionTitleWidth}mm\"></td><td width=\"" . ($this->getMainPageWidth() -  $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text</td><td></td></tr></table>";
-			$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+			$html = "<table><tr><td width=\"{$this->questionTitleWidth}mm\"></td><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth - $this->questionTitleWidth) . "mm\" class=\"responseAboveText\">$text</td><td></td></tr></table>";
+			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 		}
 
 		$currentY = $this->GetY();
 
+		$startstring = 0;
+
 		for ($i = 0; $i < $lines; $i++)
 		{
 			if ($lines == 1) $cells = $width; //one line only
 			else if (($i + 1 == $lines)) $cells = ($width - ($textResponsesPerLine * $i));  //last line
 			else $cells = $textResponsesPerLine; //middle line
 
+
 			//add another box group if moving on to another line
 			if ($i >= 1)
 				$this->addBoxGroupCopyPrevious();
 
-			$textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - (($this->textResponseWidth + $this->textResponseBorder ) * $cells);
+			$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - (($this->textResponseWidth + $this->textResponseBorder ) * $cells);
 
 			//print "textwidth: $textwidth cells: $cells mainpagex: " . $this->getMainPageX() . "<br/>";
 			//First draw a background of height $this->responseLabelHeight
 			$html = "<div></div>";
 			$this->setBackground('question');
-			$this->writeHTMLCell($this->getMainPageWidth(), $this->textResponseHeight, $this->getMainPageX(), $this->GetY() , $this->style . $html,0,1,true,false);
+			$this->writeHTMLCell($this->getColumnWidth(), $this->textResponseHeight, $this->getColumnX(), $this->GetY() , $this->style . $html,0,1,true,false);
 
 			if ($lines == 1 && $cells <= $labelTextResponsesSameLine && !empty($text))
 			{
 				$this->setDefaultFont($this->responseTextFontSize);
 
-				$this->MultiCell($textwidth,$this->textResponseHeight,$text,0,'R',false,1,$this->getMainPageX(),$currentY,true,0,false,true,$this->textResponseHeight,'M',true);
+				$this->MultiCell($textwidth,$this->textResponseHeight,$text,0,'R',false,1,$this->getColumnX(),$currentY,true,0,false,true,$this->textResponseHeight,'M',true);
 
 
 				//$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\">$text</td><td></td></tr></table>";
@@ -1810,9 +2084,15 @@ class quexmlpdf extends pdf {
 			$ncurrentY = $this->GetY();
 
 			$this->SetY($currentY,false);
-			$this->SetX($textwidth + $this->getMainPageX() + 2,false); //set the X position to the first cell
+			$this->SetX($textwidth + $this->getColumnX() + 2,false); //set the X position to the first cell
+		
+			$string = false;
+			if ($defaultvalue !== false)
+				$string = substr($defaultvalue,$startstring,$cells);
+	
+			$this->drawCells($cells,$string);
 
-			$this->drawCells($cells);
+			$startstring += $cells;
 
 			$currentY = $ncurrentY;
 
@@ -1822,9 +2102,9 @@ class quexmlpdf extends pdf {
 
 			if (!(($i + 1) == $lines) && $this->textResponseLineSpacing > 0) //if there should be a gap between text responses and not the last
 			{
-				$this->SetX($this->getMainPageX(),false);
+				$this->SetX($this->getColumnX(),false);
 				$this->setBackground('question');
-				$this->Cell($this->getMainPageWidth(),$this->textResponseLineSpacing,'','',0,'',true,'',0,false,'T','C');
+				$this->Cell($this->getColumnWidth(),$this->textResponseLineSpacing,'','',0,'',true,'',0,false,'T','C');
 				$currentY += $this->textResponseLineSpacing;
 				$this->SetY($currentY,false); //new line
 			}
@@ -1837,11 +2117,12 @@ class quexmlpdf extends pdf {
 	 * Draw X number of cells at the current X Y position
 	 *
 	 * @param int $cells  The number of text cells to draw
+	 * @param string $string A string to draw if set
 	 *
 	 * @author Adam Zammit <adam.zammit@acspri.org.au>
 	 * @since  2010-09-08
 	 */
-	protected function drawCells($cells)
+	protected function drawCells($cells, $string)
 	{
 		$this->setBackground('empty');
 		$this->SetDrawColor($this->lineColour[0]);
@@ -1870,8 +2151,12 @@ class quexmlpdf extends pdf {
 			//Add the box to the layout scheme
 			$this->addBox($this->GetX(),$this->GetY(),$this->GetX() + $this->textResponseWidth,$this->GetY() + $this->textResponseHeight);
 
+			$text = '';
+			if (isset($string[$j])) 
+				$text = $string[$j];
+
 			//Draw the box
-			$this->Cell($this->textResponseWidth,$this->textResponseHeight,'',$border,0,'',true,'',0,false,'T','C');
+			$this->Cell($this->textResponseWidth,$this->textResponseHeight,$text,$border,0,'',true,'',0,false,'T','C');
 
 		}
 
@@ -1897,7 +2182,7 @@ class quexmlpdf extends pdf {
 
 		$rwidth = ($width * ($this->textResponseWidth + $this->textResponseBorder + $this->textResponseLineSpacing));
 
-		$textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total);
+		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
 
 		$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\"></td>";
 		foreach ($subquestions as $r)
@@ -1905,18 +2190,18 @@ class quexmlpdf extends pdf {
 			$html .= "<td class=\"responseLabel\" width=\"{$rwidth}mm\">{$r['text']}</td>";
 		}
 		$html .= "<td></td></tr></table>";
-		$this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 		$currentY = $this->GetY();
 
 		$html = "<table><tr><td width=\"{$textwidth}mm\" class=\"responseText\"></td><td></td></tr></table>";
-		$this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 
 		$ncurrentY = $this->GetY();
 
 		$this->SetY($currentY,false);
 
 		//Set X position
-		$this->SetX($this->getMainPageX() + $textwidth,false);
+		$this->SetX($this->getColumnX() + $textwidth,false);	
 
 
 		foreach ($subquestions as $s)
@@ -1927,10 +2212,12 @@ class quexmlpdf extends pdf {
 			else
 				$this->addBoxGroup($bgtype,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']);
 
-
+			$string = false;
+			if (isset($s['defaultvalue'])) 
+				$string = substr($defaultvalue,0,$width);
 
 			//Draw the cells
-			$this->drawCells($width);
+			$this->drawCells($width,$string);
 
 			//Move X for a gap
 			$this->SetX($this->GetX() + $this->textResponseLineSpacing,false);
@@ -1941,17 +2228,16 @@ class quexmlpdf extends pdf {
 		$this->SetY($ncurrentY,false);
 	}
 
+
 	/**
-	 * Draw a horizontal table of respones including "eye guides"
+	 * Draw the head of a single choice horizontal table of responses
 	 *
 	 * @param array $categories The response categories
-	 * @param array $subquestions The subquestions if any
-	 * @param string|bool $parenttext The question text of the parent or false if not specified
 	 *
 	 * @author Adam Zammit <adam.zammit@acspri.org.au>
-	 * @since  2010-09-08
+	 * @since  2012-06-05
 	 */
-	protected function drawSingleChoiceHorizontal($categories, $subquestions = array(array('text' => '')),$parenttext = false)
+	protected function drawSingleChoiceHorizontalHead($categories)
 	{
 		$total = count($categories);
 		$currentY = $this->GetY();
@@ -1961,22 +2247,22 @@ class quexmlpdf extends pdf {
 		else
 			$rwidth = $this->singleResponseVerticalAreaWidth;
 
-		$textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total);
+		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
 
 
 		//First draw a background of height $this->responseLabelHeight
 		$html = "<div></div>";
 		$this->setBackground('question');
-		$this->writeHTMLCell($this->getMainPageWidth(), $this->responseLabelHeight, $this->getMainPageX(), $currentY , $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true);
 
 		$this->setDefaultFont($this->responseLabelFontSize);
 
 		$count = 0;
-		//Draw a Cell for each rwidth from $textwidth + $this->getMainPageX(),currentY
+		//Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY 
 		foreach ($categories as $r)
 		{
 			$y = $currentY;
-			$x = ($textwidth + $this->getMainPageX() + ($rwidth * $count));
+			$x = ($textwidth + $this->getColumnX() + ($rwidth * $count));
 
 			// Going to break the line because of long word
 			if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
@@ -1990,13 +2276,62 @@ class quexmlpdf extends pdf {
 
 			$count++;
 		}
+	}
+
+	/**
+	 * Draw a horizontal table of respones including "eye guides"
+	 * 
+	 * @param array $categories The response categories
+	 * @param array $subquestions The subquestions if any 
+	 * @param string|bool $parenttext The question text of the parent or false if not specified
+	 *
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2010-09-08
+	 */
+	protected function drawSingleChoiceHorizontal($categories, $subquestions = array(array('text' => '')),$parenttext = false)
+	{
+		$total = count($categories);
+		$currentY = $this->GetY();
+
+		if ($total > $this->singleResponseHorizontalMax) //change if too many cats
+			$rwidth = $this->singleResponseVerticalAreaWidthSmall;
+		else		
+			$rwidth = $this->singleResponseVerticalAreaWidth;
+
+		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
+
+		//draw the header
+		$this->drawSingleChoiceHorizontalHead($categories);
+
 		$currentY += $this->responseLabelHeight;
 
-		//reset font size
+		if ($this->allowSplittingSingleChoiceHorizontal) $this->startTransaction(); //start a transaction
+		for ($i = 0; $i < count($subquestions); $i++)
+		{
+			$s = $subquestions[$i];
+
+			if ($this->allowSplittingSingleChoiceHorizontal && $this->pageBreakOccured)
+			{
+                                $this->pageBreakOccured = false;
+                                $this->rollBackTransaction(true);
+                                $this->SetAutoPageBreak(false); //Temporarily set so we don't trigger a page break
+                                $this->fillPageBackground();
+                                $this->newPage();
+				$this->drawSingleChoiceHorizontalHead($categories);
 
+				//reset currentY
+				$currentY = $this->GetY() + $this->responseLabelHeight;
 
-		foreach ($subquestions as $s)
+				$i = $i - 2; //go back and draw subquestions on the new page
+			}
+			else
 		{
+				if ($this->allowSplittingSingleChoiceHorizontal)
+				{
+					$this->commitTransaction();
+					$this->startTransaction(); //start a transaction to allow for splitting over pages if necessary
+				}
+ 
 			//Add box group to current layout
 			if ($parenttext == false)
 				$this->addBoxGroup(1,$s['varname'],$s['text']);
@@ -2009,13 +2344,10 @@ class quexmlpdf extends pdf {
 			//Draw background
 			$html = "<div></div>";
 			$this->setBackground('question');
-			$this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseHorizontalHeight, $this->getMainPageX(), $currentY, $this->style . $html,0,1,true,true);
+				$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseHorizontalHeight, $this->getColumnX(), $currentY, $this->style . $html,0,1,true,true);	
 			$this->setDefaultFont($this->responseTextFontSize);
 
-			$this->MultiCell($textwidth,$this->singleResponseHorizontalHeight,$s['text'],0,'R',false,0,$this->getMainPageX(),$currentY,true,0,false,true,$this->singleResponseHorizontalHeight,'M',true);
-
-
-
+				$this->MultiCell($textwidth,$this->singleResponseHorizontalHeight,$s['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseHorizontalHeight,'M',true);
 
 
 			//Draw the categories horizontally
@@ -2027,7 +2359,11 @@ class quexmlpdf extends pdf {
 				else if ($rnum < $total) $num = 'middle';
 				else if ($rnum == $total) $num = 'last';
 
-				$position = $this->drawHorizontalResponseBox(($this->getMainPageX() + $textwidth + (($rnum - 1) * $rwidth)),$currentY, $num,false,false,($total > $this->singleResponseHorizontalMax));
+					$bfilled = false;
+					if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value'])
+						$bfilled = true;
+	
+					$position = $this->drawHorizontalResponseBox(($this->getColumnX() + $textwidth + (($rnum - 1) * $rwidth)),$currentY, $num,false,false,($total > $this->singleResponseHorizontalMax),$bfilled);
 
 				//Add box to the current layout
 				$this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']);
@@ -2043,7 +2379,7 @@ class quexmlpdf extends pdf {
 			$this->SetY($currentY,false);
 
 		}
-
+		}
 	}
 
 	/**
@@ -2063,7 +2399,7 @@ class quexmlpdf extends pdf {
 
 		$rwidth = $this->singleResponseVerticalAreaWidth;
 
-		$textwidth = ($this->getMainPageWidth() - $this->skipColumnWidth) - ($rwidth * $total);
+		$textwidth = ($this->getColumnWidth() - $this->skipColumnWidth) - ($rwidth * $total);
 
 		if (count($categories) > 1)
 		{
@@ -2073,16 +2409,16 @@ class quexmlpdf extends pdf {
 			//First draw a background of height $this->responseLabelHeight
 			$html = "<div></div>";
 			$this->setBackground('question');
-			$this->writeHTMLCell($this->getMainPageWidth(), $this->responseLabelHeight, $this->getMainPageX(), $currentY , $this->style . $html,0,1,true,true);
+			$this->writeHTMLCell($this->getColumnWidth(), $this->responseLabelHeight, $this->getColumnX(), $currentY , $this->style . $html,0,1,true,true);
 
 
 			$this->setDefaultFont($this->responseLabelFontSize);
 
-			//Draw a Cell for each rwidth from $textwidth + $this->getMainPageX(),currentY
+			//Draw a Cell for each rwidth from $textwidth + $this->getColumnX(),currentY 
 			foreach ($subquestions as $r)
 			{
 				$y = $currentY;
-				$x = ($textwidth + $this->getMainPageX() + ($rwidth * $count));
+				$x = ($textwidth + $this->getColumnX() + ($rwidth * $count));
 
 				// Going to break the line because of long word
 				if ($this->wordLength($r['text']) > $this->responseLabelSmallWordLength)
@@ -2122,7 +2458,7 @@ class quexmlpdf extends pdf {
 			else
 				$this->addBoxGroup(1,$s['varname'],$parenttext . $this->subQuestionTextSeparator . $s['text']);
 
-			$x = $this->getMainPageX() + $textwidth + ($rwidth * $snum) + ((($rwidth - $this->singleResponseBoxWidth) / 2.0 ));
+			$x = $this->getColumnX() + $textwidth + ($rwidth * $snum) + ((($rwidth - $this->singleResponseBoxWidth) / 2.0 ));
 
 			$other = false;
 
@@ -2140,10 +2476,10 @@ class quexmlpdf extends pdf {
 					//Draw background
 					$html = "<div></div>";
 					$this->setBackground('question');
-					$this->writeHTMLCell($this->getMainPageWidth(), $this->singleResponseAreaHeight, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+					$this->writeHTMLCell($this->getColumnWidth(), $this->singleResponseAreaHeight, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);	
 					$this->setDefaultFont($this->responseTextFontSize);
 
-					$this->MultiCell($textwidth,$this->singleResponseAreaHeight,$r['text'],0,'R',false,0,$this->getMainPageX(),$currentY,true,0,false,true,$this->singleResponseAreaHeight,'M',true);
+					$this->MultiCell($textwidth,$this->singleResponseAreaHeight,$r['text'],0,'R',false,0,$this->getColumnX(),$currentY,true,0,false,true,$this->singleResponseAreaHeight,'M',true);
 
 				}
 
@@ -2153,8 +2489,12 @@ class quexmlpdf extends pdf {
 				if (isset($r['skipto'])) $skipto = $r['skipto'];
 				if (isset($r['other']) && $rnum == $total) $other = $r['other']; //only set for last in set
 
+				$bfilled = false;
+				if (isset($s['defaultvalue']) && $s['defaultvalue'] !== false && $s['defaultvalue'] == $r['value'])
+					$bfilled = true;
+	
 				//Draw the box over the top
-				$position = $this->drawVerticalResponseBox($x,$currentY, $num, $other, $skipto);
+				$position = $this->drawVerticalResponseBox($x,$currentY, $num, $other, $skipto, $bfilled);
 
 				//Add box to the current layout
 				$this->addBox($position[0],$position[1],$position[2],$position[3],$r['value'],$r['text']);
@@ -2181,9 +2521,14 @@ class quexmlpdf extends pdf {
 			{
 				//Display the "other" variable
 				$this->addBoxGroup(3,$other['varname'],$other['text'],$other['width']);
-				$this->drawText($other['text'],$other['width']);
+
+				$defaultvalue = false;
+				if (isset($other['defaultvalue']) && $other['defaultvalue'] !== false)
+					$defaultvalue = $other['defaultvalue'];
+
+				$this->drawText($other['text'],$other['width'],$defaultvalue);
 				//Insert a gap here
-				$this->Rect($this->getMainPageX(),$this->GetY(),$this->getMainPageWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
+				$this->Rect($this->getColumnX(),$this->GetY(),$this->getColumnWidth(),$this->subQuestionLineSpacing,'F',array(),$this->backgroundColourQuestion);
 				$this->SetY($this->GetY() + $this->subQuestionLineSpacing,false);
 			}
 
@@ -2210,21 +2555,22 @@ class quexmlpdf extends pdf {
 		if (isset($this->skipToRegistry[$title]))
 			$class = "questionTitleSkipTo";
 
-		$html = "<table><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">$title</td><td class=\"questionText\" width=\"" . ($this->getMainPageWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$text</td><td></td></tr>";
+		$html = "<table><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">$title</td><td class=\"questionText\" width=\"" . ($this->getColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$text</td><td></td></tr>";
 
 		if ($specifier !== false)
 		{
-			$html .= "<tr><td></td><td></td><td></td></tr><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">&nbsp;</td><td class=\"questionSpecifier\" width=\"" . ($this->getMainPageWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$specifier</td><td></td></tr>";
+			$html .= "<tr><td></td><td></td><td></td></tr><tr><td class=\"$class\" width=\"" . $this->questionTitleWidth . "mm\">&nbsp;</td><td class=\"questionSpecifier\" width=\"" . ($this->getColumnWidth() - $this->questionTextRightMargin - $this->questionTitleWidth) . "mm\">$specifier</td><td></td></tr>";
 		}
 
 		$html .= "</table>";
 
-		$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+
+		$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 
 		if ($help != false)
 		{
-			$html = "<table><tr><td width=\"" . ($this->getMainPageWidth() -  $this->skipColumnWidth) . "mm\" class=\"questionHelp\">$help</td><td></td></tr></table>";
-			$this->writeHTMLCell($this->getMainPageWidth(), 1, $this->getMainPageX(), $this->GetY(), $this->style . $html,0,1,true,true);
+			$html = "<table><tr><td width=\"" . ($this->getColumnWidth() -  $this->skipColumnWidth) . "mm\" class=\"questionHelp\">$help</td><td></td></tr></table>";
+			$this->writeHTMLCell($this->getColumnWidth(), 1, $this->getColumnX(), $this->GetY(), $this->style . $html,0,1,true,true);
 
 		}
 	}
@@ -2251,7 +2597,7 @@ class quexmlpdf extends pdf {
 			$html .= "<div class=\"sectionInfo\">$info</div>";
 
 		$this->setBackground('section');
-		$this->writeHTMLCell($this->getPageWidth() - (($this->cornerBorder *2) + ($this->cornerWidth * 2)),$this->sectionHeight,$this->getMainPageX(),$this->getY(),$this->style . $html,array('B' => array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->backgroundColourEmpty)),1,true,true,'');
+		$this->writeHTMLCell($this->getColumnWidth(),$this->sectionHeight,$this->getColumnX(),$this->getY(),$this->style . $html,array('B' => array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => $this->backgroundColourEmpty)),1,true,true,'');
 		$this->setBackground('empty');
 	}
 
@@ -2267,19 +2613,33 @@ class quexmlpdf extends pdf {
 	}
 
 	/**
-	 * Draw the background from the current Y position to the bottom of the page
+	 * Make sure to fill the remaining columns on the last page
 	 *
-	 * @param bool $last Optional, defaults to false.  If this is the last page
+	 * @author Adam Zammit <adam.zammit@acspri.org.au>
+	 * @since  2012-05-31
+	 */
+	protected function fillLastPageBackground()
+	{
+		while ($this->columnCP < $this->columns)
+		{
+			$this->fillPageBackground();
+			$this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth));
+			$this->columnCP++;
+		}
+	}
+
+	/**
+	 * Draw the background from the current Y position to the bottom of the page
 	 *
 	 * @author Adam Zammit <adam.zammit@acspri.org.au>
 	 * @since  2010-09-15
 	 */
-	protected function fillPageBackground($last = false)
+	protected function fillPageBackground()
 	{
 		$height = $this->getPageHeight() - $this->cornerBorder - $this->GetY() + $this->questionBorderBottom;
 		$html = "<div></div>";
 		$this->setBackground('question');
-		$this->writeHTMLCell($this->getMainPageWidth(), $height, $this->getMainPageX(), $this->GetY() - $this->questionBorderBottom, $this->style . $html,0,1,true,true);
+		$this->writeHTMLCell($this->getColumnWidth(), $height, $this->getColumnX(), $this->GetY() - $this->questionBorderBottom, $this->style . $html,0,1,true,true);
 	}
 
 	/**
@@ -2288,7 +2648,11 @@ class quexmlpdf extends pdf {
 	 * Draw the barcode and page corners
 	 *
 	 */
-	protected function newPage()
+	protected function newPage($init = false) 
+	{
+		$this->columnCP++; //increment the column pointer
+
+		if ($init || ($this->columnCP >= $this->columns)) // if it is time for a new page
 	{
 		$this->AddPage();
 
@@ -2350,9 +2714,16 @@ class quexmlpdf extends pdf {
 		$this->layoutCP = $barcodeValue;
 
 		$this->SetXY($cb + $this->cornerWidth, $cb + $this->cornerWidth);
-		$this->SetAutoPageBreak(true,$this->getMainPageX());
 
 		$this->setBackground('empty');
+
+			$this->columnCP = 0; //reset column pointer
+		}
+		else // move to a new column
+		{
+			$this->SetXY($this->getColumnX(),($this->cornerBorder + $this->cornerWidth));
+		}
+		$this->SetAutoPageBreak(true,$this->getMainPageX());
 	}
 
 	/**
diff --git a/application/views/admin/export/quexmlpdf_view.php b/application/views/admin/export/quexmlpdf_view.php
index 75dc052..e74304d 100644
--- a/application/views/admin/export/quexmlpdf_view.php
+++ b/application/views/admin/export/quexmlpdf_view.php
@@ -11,5 +11,5 @@
 	span.sectionTitle {font-size:18pt; font-weight:bold;} 
 	span.sectionDescription {font-size:14pt; font-weight:bold;} 
 	div.sectionInfo {font-style:normal; font-size:10pt; text-align:left; font-weight:normal;}
-	td.questionnaireInfo {font-size:16pt; text-align:center; font-weight:bold;}
+	td.questionnaireInfo {font-size:14pt; text-align:center; font-weight:bold;}
 </style>
limesurvey-quexml-1.3.12.patch (50,616 bytes)   
quexmlpdf_view.php (943 bytes)
quexmlpdf.php (80,635 bytes)
dualmatrirx.PNG (44,211 bytes)   
dualmatrirx.PNG (44,211 bytes)   
Bug heat10
Complete LimeSurvey version number (& build)130406
I will donate to the project if issue is resolvedNo
BrowserChrome
Database type & versionMySQL 5.0.10
Server OS (if known)Win7
Webserver software & version (if known)Apache/2.4.3 (Win32)
PHP VersionPhP 5.4.7

Users monitoring this issue

adamzammit, mfaber

Activities

mfaber

mfaber

2013-04-21 03:01

reporter   ~25005

Repetition comes from the question being a DUAL matrix question. So the two matrices are apparently shown one after another instead of side by side.
This is not optimal...but ok....then again, the headings of the two matrices are missing in PDF.

Following pages being corrupt results from the question being two large for one page...this seems to be a problem happening with other question types as well (if the question does not fit one one page).

adamzammit

adamzammit

2013-04-23 07:51

developer   ~25054

I can see this problem. Some of these bugs are resolved in a newer version of the queXMLPDF class. I'll test out upgrading the class in Limesurvey and if it doesn't cause any regressions I'll insert it in to the Limesurvey repository.

adamzammit

adamzammit

2013-04-24 08:02

developer   ~25102

Dear mfaber,

Please try applying this patch (upgrading to queXML 1.3.12 with allowSplittingSingleChoiceHorizontal enabled). The PDF should come up without the page problems (your error 1 and 2). The issue with dual matrices not being displayed after instead of side by side is due to queXML not supporting them. If you are able to look through the code you may be able to patch it in - alternatively contact the queXML mailing list with a feature request.

Regards,
Adam Zammit

mfaber

mfaber

2013-04-24 18:24

reporter   ~25121

Thanks for the quick reaction and the patch, Adam! Very much appreciated! Would it be possible to provide me with the complete (patched) file(s)? Or incorporate it into the next limesurvey build?
Guess I do not know how to apply these diffs... Sorry, M

adamzammit

adamzammit

2013-04-26 04:01

developer   ~25135

Dear mfaber,

That is no problem. I've attached the files quexmlpdf.php and quexmlpdf_view.php to replace application/libraries/admin/quexmlpdf.php and application/views/admin/export/quexmlpdf_view.php

Please let me know the result of your testing.

Regards,
Adam Zammit

mfaber

mfaber

2013-04-26 10:13

reporter   ~25138

Last edited: 2013-04-26 10:15

Dear Adam,

thanks for providing the new files, which I used to overwrite the ones in the directories stated in your message. I then used the attached lss again to produce the PDF.

The good news: The problem with the page breaks seems to be solved (error 2). Thank you very much for that!!

However, there is still one problem remaining and a new one:
1) The headings of the two columns are still missing in the pdf. I attached a screenshot of the respective ONLINE questionnaire so you can see what I mean. The respective texts are entered in the advanced settings of the dual matrix question.

2) The question (question A3) now appears two times. With the headings missing I cannot tell if it is four times the first column or each column two times...I attached the PDF produced with the test questionnaire (_new.pdf).

regards
M

adamzammit

adamzammit

2013-04-30 07:31

developer   ~25171

Dear mfaber,

Regarding point 1:

The headings are not exported to queXML by Limesurvey because queXML doesn't support them. Unfortunately at this time, if you want your paper and web questionnaires to be the same, you will have to re-write your question to not be in dual matrix form. Alternatively you could export the queXML file from Limesurvey, and modify it to be 2 questions, then create a PDF from the updated queXML document. If you want this supported - I'd suggest handling it on the queXML mailing list instead.

Regarding point 2:

I am not sure why this is occurring. I have tested it using the provided LSS file and only get one "copy" of question "A3". I have seen things like this in the past that were related to the way TCPDF behaves on particular versions of PHP. My suggestion regarding point 1 may solve this incidentally if you choose to modify your question type though.

Regards,
Adam Zammit

mfaber

mfaber

2013-08-26 17:10

reporter   ~26085

Last edited: 2013-08-26 17:11

Dear Adam,

would you consider upgrading Limesurvey to the new quexml-class (see http://bugs.limesurvey.org/view.php?id=7785#c25054)? The problem with the page breaks was solved with your file but now bugs me again in 2.05 :).

I can also use the file provided by you and open a pull request. Whatever you prefer.

Thanks,
M

adamzammit

adamzammit

2013-08-30 06:47

developer   ~26111

Dear Mfaber,

It would be great if you could test it locally and open a pull request if it works fine.

Regards,
Adam Zammit

mfaber

mfaber

2013-08-31 20:03

reporter   ~26120

Dear Adam,

Took me a while to understand how all this works ;) and get the page breaks right. I tested it with two large questionnaires and it seems to work fine.

Issued the pull request at: https://github.com/LimeSurvey/LimeSurvey/pull/117

regards,
Mirko

adamzammit

adamzammit

2013-09-02 07:46

developer   ~26123

Fix committed to 2.05 branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=12927

mfaber

mfaber

2013-09-09 16:57

reporter   ~26192

Dear Adam,
i further improved the pagination of quexf in connection with matrix questions.
There was still an issue with this question type when the end of page was reached within the question text. Now, the question text, the category labels and the first subquestion needs to fit on one page, otherwise the new page is begun before the question starts.
Could you merge this pull request?

https://github.com/LimeSurvey/LimeSurvey/pull/123

Thanks,
Mirko

adamzammit

adamzammit

2013-09-11 08:20

developer   ~26199

Dear Mirko,

I would like to make changes such as this upstream in the queXML package so I can test them on some more forms before pushing it out to Limesurvey. I'll make a patch myself for queXML and review it and if it looks good - I'll commit the pull request and also update queXML.

Regards,
Adam Zammit

mfaber

mfaber

2013-09-11 13:29

reporter   ~26200

Dear Adam,

that's perfectly fine with me. I think Sam already did the merge but if something's not to your liking feel free to make the changes or give me a sign and I will do it and issue another pull request.

I am planning on updating quexf-export further so matrix questions (text matrix, number matrix and dual matrix) are better supported. At the moment some labels are missing and this question type can not really be used in conjunction with quexf exports. When i'm ready, I would issue another pull request with a note that it should be reviewed and "cleared" by you. Is that ok?

regards,
Mirko

adamzammit

adamzammit

2013-09-16 04:22

developer   ~26240

Hi Mirko,

Thanks for that. I don't want to hold up your development so I'm happy for you to proceed without working upstream. It would be great to keep me notified of changes though as then I can manage the process upstream.

Regards,
Adam Zammit

mfaber

mfaber

2013-09-16 14:43

reporter   ~26252

Cool, i'll then have you "monitor" the respective threads in this bugtracker and in github... That means if I find more things to do in quexf. :)

Just have to say that quexf is a terrific addition to limesurvey which no other software package i am aware of offers. Not only and specifically for OMR but also for having a printout of your questionnaire that looks very professional!
So thanks for that and don't you dare to abandon this project ;)
M

c_schmitz

c_schmitz

2013-09-24 14:20

administrator   ~26343

2.05RC1 released

Related Changesets

LimeSurvey: 2.05 8235c5ce

2013-09-02 05:46:38

adamzammit

Details Diff
Merge pull request #117 from mfaber/updatequexf205

Fixed issue 07785: Problem with page breaks in quexf-PDF
Affected Issues
07785
mod - application/libraries/admin/quexmlpdf.php Diff File

Issue History

Date Modified Username Field Change
2013-04-21 02:34 mfaber New Issue
2013-04-21 02:34 mfaber File Added: limesurvey_survey_PDF.lss
2013-04-21 02:37 mfaber File Added: quexmlpdf_457591_de.pdf
2013-04-21 02:38 mfaber Issue Monitored: mfaber
2013-04-21 03:01 mfaber Note Added: 25005
2013-04-22 00:38 c_schmitz Assigned To => adamzammit
2013-04-22 00:38 c_schmitz Status new => assigned
2013-04-23 07:51 adamzammit Note Added: 25054
2013-04-23 07:51 adamzammit Status assigned => acknowledged
2013-04-24 07:59 adamzammit File Added: limesurvey-quexml-1.3.12.patch
2013-04-24 08:02 adamzammit Note Added: 25102
2013-04-24 08:04 adamzammit Issue Monitored: adamzammit
2013-04-24 18:24 mfaber Note Added: 25121
2013-04-26 03:59 adamzammit File Added: quexmlpdf_view.php
2013-04-26 04:00 adamzammit File Added: quexmlpdf.php
2013-04-26 04:01 adamzammit Note Added: 25135
2013-04-26 10:13 mfaber Note Added: 25138
2013-04-26 10:13 mfaber File Added: dualmatrirx.PNG
2013-04-26 10:14 mfaber File Added: quexmlpdf_457591_de_new.pdf
2013-04-26 10:15 mfaber Note Edited: 25138
2013-04-30 07:31 adamzammit Note Added: 25171
2013-08-26 17:10 mfaber Note Added: 26085
2013-08-26 17:11 mfaber Note Edited: 26085
2013-08-30 06:47 adamzammit Note Added: 26111
2013-08-31 20:03 mfaber Note Added: 26120
2013-08-31 20:04 mfaber Resolution open => fixed
2013-09-02 07:46 adamzammit Changeset attached => LimeSurvey 2.05 8235c5ce
2013-09-02 07:46 adamzammit Note Added: 26123
2013-09-02 17:45 mfaber Status acknowledged => resolved
2013-09-09 16:57 mfaber Note Added: 26192
2013-09-11 08:20 adamzammit Note Added: 26199
2013-09-11 13:29 mfaber Note Added: 26200
2013-09-16 04:22 adamzammit Note Added: 26240
2013-09-16 14:43 mfaber Note Added: 26252
2013-09-23 13:35 c_schmitz Fixed in Version => 2.05 RC
2013-09-24 14:20 c_schmitz Note Added: 26343
2013-09-24 14:20 c_schmitz Status resolved => closed
2021-08-02 20:03 guest Bug heat 6 => 10