tcPDF的混乱输出

时间:2017-07-05 03:22:50

标签: php phpexcel tcpdf

我正在尝试阅读.xlsx模板,更改其部分内容并将其保存为pdf文件。为此,我使用PHPExcel和tcPDF作为PDF渲染器。问题是,我无法正确获得输出。这是我使用的代码:

include_once "../class/PHPExcel.php";
include_once "../class/PHPExcel/IOFactory.php";
include_once "../class/PHPExcel/Cell.php";
include_once "../class/PHPExcel/Worksheet/MemoryDrawing.php";
include_once "../class/PHPExcel/Settings.php";

$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
$libraryPath = "../class/tcpdf_6_2_13/tcpdf_isee";
PHPExcel_Settings::setPdfRenderer($rendererName, $libraryPath);

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$fileTemplate = $reader->load("1 Lambung (A Dokumentasi dan gambar rencana).xlsx");
$fileTemplate->setActiveSheetIndex(0);

$fileTemplate->getActiveSheet()->setShowGridlines(false);
$fileTemplate->getActiveSheet()->setCellValueExplicitByColumnAndRow(6, 24, "N");
$fileTemplate->getActiveSheet()->setCellValueExplicitByColumnAndRow(6, 28, "N");

$writer = PHPExcel_IOFactory::createWriter($fileTemplate, 'pdf');
$writer->save("1 Lambung (A Dokumentasi dan gambar rencana)ed.pdf");

我还对PHPExcel_Writer_PDF_tcPDF进行了一些更改,如下所示(我只添加一行来设置单元格高度比,将单位更改为英寸并删除72 dpi转换):

//  Create PDF
    $pdf = new TCPDF($orientation, 'in', $paperSize);
    $pdf->setFontSubsetting(false);
    //    Set margins, converting inches to points (using 72 dpi)
    $pdf->SetMargins($printMargins->getLeft(), $printMargins->getTop(), $printMargins->getRight());
    $pdf->SetAutoPageBreak(true, $printMargins->getBottom());
    $pdf->setCellHeightRatio(0.8);

这是模板的屏幕截图:

Excel Template

这些是pdf输出:

PDF Output page 1

很抱歉给您带来不便,由于声誉不佳,我仍然无法嵌入图片。

总结一下,输出中存在问题:

  • 线条之间有很大的间距。我试图通过使用setCellHeightRatio方法降低细胞高度比来修复它。它适用于在它们之间有空行的行,但对于彼此相邻的行,内容将重叠。作为最后的手段,我将尝试修改模板,但是现在我仍然认为问题在于我的代码
  • 页边距大于原始模板中设置的页边距
  • 表格边框的线宽与原始模板不同。我尝试使用setLineWidth设置线宽,但没有效果
  • 单元格的某些内容被推送到下一行

有人可以帮我吗?

0 个答案:

没有答案