我在創建TCPDF中的表格時遇到了一些問題,其中除第一個和最後一個之外的所有標題列都應旋轉90度(或者:單元格中的文本應爲垂直)。TCPDF:旋轉表頭中的文本/單元格
有沒有辦法在一個單元格內旋轉測試,而不是完整的單元格本身?
我想表看起來像這樣:
感謝您的幫助。
我在創建TCPDF中的表格時遇到了一些問題,其中除第一個和最後一個之外的所有標題列都應旋轉90度(或者:單元格中的文本應爲垂直)。TCPDF:旋轉表頭中的文本/單元格
有沒有辦法在一個單元格內旋轉測試,而不是完整的單元格本身?
我想表看起來像這樣:
感謝您的幫助。
很簡單的一,請檢查下面的代碼。
$pdf->StartTransform();
$pdf->Rotate(-90);
$pdf->Cell(0,0,'This is a sample data',1,1,'L',0,'');
$pdf->StopTransform();
使用MultiCell並給出寬度時,在StopTransform()之後,下一個單元格開始旋轉,如同旋轉的單元格是水平的。這意味着在旋轉的單元格和下一個水平單元格之間存在空格。你明白我想說什麼嗎? X_X幫助我請! – JhovaniC
我在過去2周裏在這個問題上努力工作。
TCPDF標記在調用Rotate方法時效果很好,但不是我不喜歡。 我的解決方案是:
現在,代碼示例...
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Test($ae) {
if(!isset($this->xywalter)) {
$this->xywalter = array();
}
$this->xywalter[] = array($this->GetX(), $this->GetY());
}
}
// create new PDF document
$pdf = new MYPDF('L', PDF_UNIT, 'A1', true, 'UTF-8', false);
// set Rotate
$params = $pdf->serializeTCPDFtagParameters(array(90));
// other configs
$pdf->setOpenCell(0);
$pdf->SetCellPadding(0);
$pdf->setCellHeightRatio(1.25);
// create some HTML content
$html = '<table width="100%" border="1" cellspacing="0" cellpadding="5">
<thead>
<tr bgcolor="#E6E6E6">
<th rowspan="2" width="15%" align="center">ATIVIDADES E PROCESSOS</th>
<th rowspan="2" width="10%" align="center" valign="bottom">ASPECTOS</th>
<th rowspan="2" width="10%" align="center">IMPACTOS</th>
<th colspan="3" width="6%" align="center">MEIO</th>
<th rowspan="2" width="3%" align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th colspan="9" width="18%" align="center">CLASSIFICAÇÕES</th>
<th rowspan="2" width="3%" align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th rowspan="2" width="10%" align="center">PROGRAMA</th>
<th rowspan="2" width="10%" align="center">SUBPROGRAMA</th>
<th rowspan="2" width="15%" align="center">AÇÕES DE CONTROLE, MEDIDAS MITIGADORAS, COMPENSATÓRIAS E POTENCIALIZADORAS</th>
</tr>
<tr bgcolor="#E6E6E6">
<th align="center" height="200"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
<th align="center"><tcpdf method="Test" params="'.$params.'" /></th>
</tr>
</thead>
<tr bgcolor="#E6E6E6">
<td colspan="20" align="center">Planejamento</td>
</tr>
<tr bgcolor="#FFFFFF">
<td rowspan="3" width="15%" align="left" bgcolor="#FFFFFF">Divulgação do empreendimento</td>
<td rowspan="2" width="10%" align="left">Oferta de empregos diretos e indiretos</td>
<td rowspan="2" width="10%" align="left">Atração de população para as comunidades do entorno</td>
<td rowspan="2" width="2%" align="center"></td>
<td rowspan="2" width="2%" align="center"></td>
<td rowspan="2" width="2%" align="center">X</td>
<td rowspan="2" width="3%" align="center">AII</td>
<td rowspan="2" width="2%" align="center">-</td>
<td rowspan="2" width="2%" align="center">Ind</td>
<td rowspan="2" width="2%" align="center">T</td>
<td rowspan="2" width="2%" align="center">Mp</td>
<td rowspan="2" width="2%" align="center">Po</td>
<td rowspan="2" width="2%" align="center">D</td>
<td rowspan="2" width="2%" align="center">R</td>
<td rowspan="2" width="2%" align="center">M</td>
<td rowspan="2" width="2%" align="center">M</td>
<td rowspan="2" width="3%" align="center">M</td>
<td width="10%">Programa de Apoio ao Desenvolvimento Socioeconomico da Região</td>
<td width="10%">Subprograma de Apoio ao Desenvolvimento Habitacional</td>
<td width="15%">Coibir ocupação indevida de áreas inadequadas</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Programa de Comunicação Social</td>
<td> -</td>
<td>Ações de comunicação sobre o empreendimento e questões ambientais</td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="left">Geração de expectativas na população</td>
<td align="left">Geração de expectativas junto a população</td>
<td align="center"></td>
<td align="center"></td>
<td align="center">X</td>
<td align="center">AII</td>
<td align="center">-</td>
<td align="center">Dir</td>
<td align="center">T</td>
<td align="center">Im</td>
<td align="center">Co</td>
<td align="center">L</td>
<td align="center">R</td>
<td align="center">P</td>
<td align="center">P</td>
<td align="center">B</td>
<td>Programa de Comunicação Social</td>
<td> -</td>
<td>Ações de comunicação sobre o empreendimento e questoes ambientais</td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// array with names of columns
$arr_nomes = array(
array("ABRANGÊNCIA", 8, 59), // array(name, new X, new Y);
array("SIGNIFICÂNCIA", 8, 59),
array("FÃSICO", 4, 52),
array("BIÃ「TICO", 4, 52),
array("SOCIOECONÃ」MICO", 4, 52),
array("NATUREZA", 4, 52),
array("ORIGEM", 4, 52),
array("DURAÇÃO", 4, 52),
array("OCORRÊNCIA/TEMPORALIDADE", 4, 52),
array("FREQUÊNCIA", 4, 52),
array("ESPACIALIZAÇÃO", 4, 52),
array("REVERSIBILIDADE", 4, 52),
array("MAGNITUDE", 4, 52),
array("RELEVÂNCIA", 4, 52)
);
// num of pages
$ttPages = $pdf->getNumPages();
for($i=1; $i<=$ttPages; $i++) {
// set page
$pdf->setPage($i);
// all columns of current page
foreach($arr_nomes as $num => $arrCols) {
$x = $pdf->xywalter[$num][0] + $arrCols[1]; // new X
$y = $pdf->xywalter[$num][1] + $arrCols[2]; // new Y
$n = $arrCols[0]; // column name
// transforme Rotate
$pdf->StartTransform();
// Rotate 90 degrees counter-clockwise
$pdf->Rotate(90, $x, $y);
$pdf->Text($x, $y, $n);
// Stop Transformation
$pdf->StopTransform();
}
}
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_006.pdf', 'I');
我不得不接受其他答案,因爲我沒有使用HTML表格。但我相信這也是一個體面的解決方案。感謝那。 – Thorsten
'setPage()函數的錯誤頁碼:0'找不到原因。 –
這是一個老的討論,但我仍然面臨這個問題。我在我的TCPDF分支上做了一個解決方法。 http://sourceforge.net/u/mnicolardi/tcpdf/ci/master/tree/
我已經添加了一個參數,告訴MultiCell方法它在90度旋轉環境中運行。在這種情況下,它使用$ h將單元格移動到右側。
新的方法原型爲:
public function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false,$rotated90Degrees=false)
用例:
$pdf->StartTransform();
$pdf->Rotate(90);
$pdf->MultiCell(100, 10, "rotated text", 1, 'C', false, 0, "", "", true, 0, false, true, 0, "T", false, true);
$pdf->StopTransform();
希望它能幫助!
你是對的,完全忘記了這個問題,因爲我不再在相關產品上工作。 – Thorsten