उपयोग TCPDF उदाहरण 20
गिना जा रहा है MultiCell ऊंचाइयों एक बुरा सपना कोशिकाओं/कॉलम विभिन्न पृष्ठों पर खत्म करता है, तो हो सकता है।
लेनदेन या अतिरिक्त पीडीएफ ऑब्जेक्ट्स का उपयोग करके चीजें बहुत धीमी हो सकती हैं।
कोशिकाओं मुद्रित होने से पहले 'अनुमानित' (दस्तावेज़ देखें) ऊंचाई की गणना करने के लिए getNumLines() और getStringHeight() जैसे कार्यों का उपयोग करना हमेशा सही ढंग से काम नहीं करता है। विशेष रूप से यदि पाठ सेल की दाएं सीमा के ठीक पहले या बस समाप्त होता है - जिसके परिणामस्वरूप पंक्तियों को एक दूसरे के शीर्ष पर मुद्रित किया जाता है।
मैं Example 20 में इस्तेमाल तकनीक जहां विभिन्न पृष्ठों की अधिकतम Y मान नई पंक्ति की स्थिति की गणना करने के लिए उपयोग किया जाता है पसंद करते हैं।
उदाहरण केवल दो कॉलम प्रिंट करता है, लेकिन मैंने कॉलम की एक सरणी मुद्रित करने में सक्षम होने के लिए अपना मुख्य कार्य बदल दिया। जाहिर है आप इस तरह के प्रत्येक स्तंभ के फ़ॉन्ट, बॉर्डर, आदि
public function MultiRow($columnsArray) {
$page_start = $this->getPage();
$y_start = $this->GetY();
$pageArray = array();
$yArray = array();
// traverse through array and print one column at a time.
$columnCount = count($columnsArray);
for($i=0; $i<$columnCount; $i++)
{
if($i+1 < $columnCount)
{
// Current column is not the last column in the row.
// After printing, the pointer will be moved down to
// the right-bottom of the column - from where the
// next multiCell in the following loop will use it
// via $this->GetX().
$ln = 2;
}
else
{
// Current column is the last column in the row.
// After printing, the pointer will be moved to new line.
$ln = 1;
}
$this->MultiCell(30, 0, $columnsArray[$i], 1, 'L', 1, $ln,
$this->GetX() ,$y_start, true, 0);
$pageArray[$i] = $this->getPage();
$yArray[$i] = $this->GetY();
// Go to page where the row started - to print the
// next column (if any).
$this->setPage($page_start);
}
// Test if all columns ended on the same page
$samePage = true;
foreach ($pageArray as $val) {
if($val != $pageArray['0'])
{
$samePage = false;
break;
}
}
// Set the new page and row position by case
if($samePage == true)
{
// All columns ended on the same page.
// Get the longest column.
$newY = max($yArray);
}
else
{
// Some columns ended on different pages.
// Get the array-keys (not the values) of all columns that
// ended on the last page.
$endPageKeys = array_keys($pageArray, max($pageArray));
// Get the Y values of all columns that ended on the last page,
// i.e. get the Y values of all columns with keys in $endPageKeys.
$yValues = array();
foreach($endPageKeys as $key)
{
$yValues[] = $yArray[$key];
}
// Get the largest Y value of all columns that ended on
// the last page.
$newY = max($yValues);
}
// Go to the last page and start at its largets Y value
$this->setPage(max($pageArray));
$this->SetXY($this->GetX(),$newY);
}
स्रोत
2015-10-22 10:03:53
दोनों getNumLines() और getStringHeight (के रूप में सरणी के लिए और अधिक डेटा जोड़ सकता है,) केवल एक 'अनुमानित ऊंचाई' (डॉक्स देखें) दे। यह कार्य हमेशा सही ढंग से काम नहीं करते हैं यदि पाठ सेल की दाएं सीमा के ठीक पहले या बस समाप्त होता है - जिसके परिणामस्वरूप पंक्तियों को एक दूसरे के शीर्ष पर मुद्रित किया जाता है। इसके बजाय तकनीक का उपयोग करें उदाहरण के लिए 20. –