如何在codeigniter中使用PdfCrowd Api?

时间:2017-10-18 10:55:14

标签: codeigniter

Hello Iam使用pdfCrowd Api转换为pdf。如果我使用convertfile指定视图它说路径无效?如何将视图传递给pdfCrowd的转换文件功能?



function download() { require('pdfcrowd.php'); $user_id=$this->session->userdata('user_id'); $data = array(); $data['result']=$this->user_data_model->getcertificate($user_id); try { // create an API client instance $client = new Pdfcrowd('username','api');
// convert a web page and store the generated PDF into a $pdf variable $pdf = $client->convertFile('certificate_template'); // set HTTP response headers header("Content-Type: application/pdf"); header("Cache-Control: max-age=0"); header("Accept-Ranges:
none"); header("Content-Disposition: attachment; filename=\"google_com.pdf\""); // send the generated PDF echo $pdf; } catch(PdfcrowdException $why) { echo "Pdfcrowd Error: " . $why; } }






function download() { 
	        require('pdfcrowd.php');
            $user_id=$this->session->userdata('user_id');
            $data = array();
            $data['result']=$this->user_data_model->getcertificate($user_id);
			
			try
			{   
				// create an API client instance
				$client = new Pdfcrowd('username','api');

				// convert a web page and store the generated PDF into a $pdf variable
				$pdf = $client->convertFile('certificate_template');

				// set HTTP response headers
				header("Content-Type: application/pdf");
				header("Cache-Control: max-age=0");
				header("Accept-Ranges: none");
				header("Content-Disposition: attachment; filename=\"google_com.pdf\"");

				// send the generated PDF 
				echo $pdf;
			}
			catch(PdfcrowdException $why)
			{
				echo "Pdfcrowd Error: " . $why;
			}
		
        
	}




1 个答案:

答案 0 :(得分:0)

convertFile方法仅接受本地HTML文件,不能作为模板。

您有2个选择:

  • 在您呈现的模板中使用convertURI而不是convertFile

  • 将模板渲染为临时的本地HTML文件,并在convertFile方法中使用它