2017-06-25 1 views
3

私は履歴書ビルダーアプリケーションを作成しました。すべての必要な詳細が入力され、すべての詳細がデータベースに保存されています。次に、私はそれらのレコードを取得し、別のテンプレートで表示しています。私は3つのテンプレートを作成しました。今私はpdfとしてダウンロードを与え、docxとして2つのダウンロードボタンをダウンロードしたいと思う。ユーザーが任意のボタンをクリックすると、ファイルは選択された形式でダウンロードされます。 pdfまたはdocxのいずれか。codeigniterのダウンロードボタンをクリックした後にhtmlをpdfに変換する

codeigniterで実現することはできますか?

私は

TCPDF

使用コントローラコードは、あなたがこれを達成するためにCIにいくつかのライブラリを使用する必要があります。おそらく

the code written in controller download $this - > load - > library("Pdf"); 
 
// create new PDF document 
 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
 
// set auto page breaks 
 
$pdf - > SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 
 
// set image scale factor 
 
$pdf - > setImageScale(PDF_IMAGE_SCALE_RATIO); 
 
// Add a page 
 
// This method has several options, check the source code documentation for more information. 
 
$pdf - > AddPage(); 
 
// Set some content to print 
 
$html = $this - > load - > view('resume/res_template1_view', array('left_sidebar' => 'sidebar/left_sidebar', '    right_sidebar' => 'sidebar/right_sidebar'), $data, TRUE); 
 
// Print text using writeHTMLCell() 
 
$pdf - > writeHTML($html, 0, 0, '', '', 0, 1, 0, true, '', true); 
 
//$pdf->writeHTML($html, true, false, true, false, ''); 
 

 
// Close and output PDF document 
 
// This method has several options, check the source code documentation for more information. 
 
$pdf - > Output('resume.pdf', 'D');

+0

「php html2pdf」のようなもののGoogle '.docx'ファイルに関しては、' PHPOffice/PHPWord'を選択することができます。 – Tpojka

+0

https://parall.ax/products/jspdf thisも使用できます。非常によく文書化されています。 – molagbal

+0

Mpdf「https:// davidsimpson.me/2013/05/19/using-mpdf-with-codeigniter /」または「http://www.w3school.info/2016/02/08/convert-html」を使用できます-pdf-in-codeigniter-using-mpdf/' –

答えて

0

です。下記をご確認ください。 CI3ライブラリにHtml2Pdfを使用できます。

あなたがPDFを作成するために設定するために必要な4つのオプションがあります使用方法https://github.com/shyamshingadiya/HTML2PDF-CI3

。フォルダ、ファイル名、紙やHTML

//Load the library 
$this->load->library('html2pdf'); 

//Set folder to save PDF to 
$this->html2pdf->folder('./assets/pdfs/'); 

//Set the filename to save/download as 
$this->html2pdf->filename('test.pdf'); 

//Set the paper defaults 
$this->html2pdf->paper('a4', 'portrait'); 

//Load html view 
$this->html2pdf->html(<h1>Some Title</h1><p>Some content in here</p>); 

関数は、2つのオプション'save''download'を持って作成します。保存すると、設定で選択したフォルダにPDFが書き込まれます。ダウンロードは、PDFをクライアントブラウザにダウンロードさせます。

//Create the PDF 
$this->html2pdf->create('save'); 

高度な使用法

Theresのビルドとhtml()機能にビューを渡すことができない理由理由はありません。 'save'オプションを選択した場合、create()関数は保存されたパスを返します。

$data = array(
    'title' => 'PDF Created', 
    'message' => 'Hello World!' 
); 

//Load html view 
$this->html2pdf->html($this->load->view('pdf', $data, true)); 

if($path = $this->html2pdf->create('save')) { 
    //PDF was successfully saved or downloaded 
    echo 'PDF saved to: ' . $path; 
} 

上記の解決策を確認してください。それが動作しない場合私に教えてください。

+0

Tcpdfを使用しました。適切にダウンロードしてください。しかし、ダウンロードしたpdfファイルは、$ this-> load-> viewを$ html変数に渡すと空になります。 –

+0

もし私が$ htmlに直接HTMLを書いているのであれば、ダウンロードしたpdfにhtmlのCSS値が入っています –

+0

あなたのコードを教えてください。 –

関連する問題