Convert excel file to pdf file

Topics: Developer Forum, User Forum
Apr 15, 2010 at 1:23 AM

Hi all,

How is it going?

I made one excel report file which has got 5 tabs at the bottom by using php, but my client wants report as a pdf file rather than excel file so I changed objWriter like as below

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');

and I changed file format as pdf, then I can see the report as pdf file but it shows only first tab contents on pdf file.

How can I show all tabs' contents? and I would like to do page break for each tab as well.

Also when I open a pdf report file, then I found out that image and text are too big, so some stuff is cut at right side, for that I would like to fix that problem too.

I need your help guys! Please help me out at this stage.

I need to fix this asap.

  

Thanks

 

Apr 15, 2010 at 2:20 AM
Edited Apr 15, 2010 at 6:07 AM

From my understanding, I need to save html file first then read that file to convert into pdf, but the error message saying that "file is damaged"

The below code is download button action : please ignore font stuff

$time = date("dmY"); "Pragma: public");

$filename = 'LSP_Report_'.$time.'.HTML;

$writer = PHPExcel_IOFactory::createWriter($excel, 'HTML');
$writer->setUseInlineCSS(true);
$writer->save($filename );

$pdf = new HTMLTOPDF_Topdf($filename,'mm','test.pdf');

$pdf->convert();

header("Pragma: public"); 

header("Expires: 0");

header("Content-Type: application/force-download");

header("Content-Type: application/octet-stream");

header("Content-Type: application/download");

header("Content-Disposition: attachment; filename=test.pdf");

header("Content-Transfer-Encoding: binary");

 

 

 

 

 

Coordinator
Apr 15, 2010 at 9:40 AM
Edited Apr 15, 2010 at 9:52 AM

How can I show all tabs' contents? and I would like to do page break for each tab as well.

$fileType = 'Excel5';
$fileName = 'test.xls';
$outputFileType = 'PDF';
$outputFileName = 'test.pdf';
$objPHPExcel = PHPExcel_IOFactory::load($fileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $outputFileType);
$objWriter->writeAllSheets();
$objWriter->save($outputFileName);
Also when I open a pdf report file, then I found out that image and text are too big, so some stuff is cut at right side, for that I would like to fix that problem too.

Around line 110 of Classes/PHPExcel/Writer/PDF.php
 // Default PDF paper size
     $paperSize = 'A4';
     $orientation = 'P';
You can change the paper size by modifying the code: we should probably provide a method to do this, but it doesn't exist yet.
And use the $objPHPExcel->getSheet($index)->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
to set the page orientation to landscape.

You might look at 
$objPHPExcel->getSheet($index)->getPageSetup()->setPaperSize() for each tab index as an alternative to changing the $paperSize value in PDF.php, but I'm not sure it works with the PDF exporter
Also, take a look at 
$objPHPExcel->getSheet($index)->getPageSetup()->setFitToPage() and the other page scaling methods
Apr 16, 2010 at 3:51 AM
Edited Apr 16, 2010 at 5:22 AM

Hi,

Thank you for your response, and now it's working part of it.

I made some borders for my table, and it's not showing on pdf file, only data is showing, do you know how to show the border of table as below code?

 

 

and also now it's almost fit into the page, but not 100% like 90% showing. Some 10% data where is positioned on right is cut.

Could you please tell me how to fit this into pdf like showing whole data?

Thanks

 

 

 

 

<font size="2" color="#660000">

$styleThinBlueBorderOutline

</font>

 

= array

(<font size="2">

 

</font>

'borders' => array

(<font size="2">

 

</font>

'outline' => array

(<font size="2">

 

</font>

'style'

=> PHPExcel_Style_Border::BORDER_THIN,<font size="2">

 

</font>

'color' => array('argb' => '000000'

),

),

),

<font size="2">

);

</font>

 

$objPHPExcel->getActiveSheet()->getStyle('B6')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('A7')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('B7')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('A8')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('B8')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('A9')->applyFromArray($styleThinBlueBorderOutline);

 

$objPHPExcel->getActiveSheet()->getStyle('B9')->applyFromArray($styleThinBlueBorderOutline);

</font>$objPHPExcel->getActiveSheet()->getStyle('A6')->applyFromArray($styleThinBlueBorderOutline);