2013-07-05 4 views
0

enter image description here 아래의 코드를 실행 한 후에도 브라우저 PDF 출력과 함께 PDF 다운로드가 표시되지 않습니다. 빈 페이지 표시.PHPExcel PDF Writer가 작동하지 않습니다.

require_once 'Classes/PHPExcel/IOFactory.php'; 
$objPHPExcel = new PHPExcel(); 
$objPHPExcel->getActiveSheet()->setCellValue('c9','40'); 

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); 
//You need to include and print to PDF the entire worksheets contained in the workbook 
$objWriter->writeAllSheets(); 

//You need to assign a filename to the PDF file (write.pdf for example) 
header('Content-type:Application/pdf'); 
header('Content-Disposition: attachment;filename="export.pdf"'); 
$objWriter->save('php://output'); 

여전히 코드에는 약간의 실수가 있습니다. 브라우저에서 PDF를 보는 동안 다운로드 할 수 없습니다. 첨부 된 스크린 샷을 찾으십시오.

마지막으로 당신은 파일에 PDF를 작성하는 문제를

+0

헤더 ('콘텐츠 유형을 : 응용 프로그램/pdf '); 이것을 설정하고 write.pdf를 다운로드하는 대신에 – Satya

+0

이 작동하는지 확인하십시오. sample.php가 다운로드 중입니다. 빈 웹 페이지를 브라우저에 표시합니다. – Bharanikumar

+0

PHPExcel에서 사용중인 PDF 렌더링 라이브러리를 식별하고 있습니까? 나는 그 어떤 코드도 보지 않았기 때문에! –

답변

2

을 고정 위의 코드 :

$objWriter->save('write.pdf'); 

브라우저에이 출력하지 않습니다 아무것도, 또는 다운로드를 트리거합니다. 너는 그걸 너 자신의 애버뉴처럼 버려야 해.

readfile('write.pdf'); 

또는 PDF를 만들기 전에 먼저 제공해야

$objWriter->save('php://output'); 
+0

이 스크린 샷을 추가하여 좀 더 잘 설명해줍니다. – Bharanikumar

+0

plz 답변에 대한 제안을 게시하십시오. – Bharanikumar

+0

if this "header ('Content-Disposition : attachment; filename ="export.pdf "');"를 제거하면 PDF 대신 응용 프로그램 PHP 파일이 다운로드됩니다. – Bharanikumar

0

헤더에 저장() 호출을 변경 :이 시도 :

require_once 'Classes/PHPExcel/IOFactory.php'; 
$objPHPExcel = new PHPExcel(); 
$objPHPExcel->getActiveSheet()->setCellValue('c9','40'); 
//Create the header first before Writing PDF 
header('Content-type:Application/pdf'); 
header('Content-Disposition: attachment;filename="export.pdf"'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); 
//You need to include and print to PDF the entire worksheets contained in the workbook 
$objWriter->writeAllSheets(); 
$objWriter->save('php://output'); 
관련 문제