File tree Expand file tree Collapse file tree 5 files changed +66
-3
lines changed
src/PhpSpreadsheet/Writer/Pdf Expand file tree Collapse file tree 5 files changed +66
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212- Support for chart fill color - @CrazyBite [ #158 ] ( https://github.com/PHPOffice/PhpSpreadsheet/pull/158 )
1313- Support for read Hyperlink for xml - @GreatHumorist [ #223 ] ( https://github.com/PHPOffice/PhpSpreadsheet/pull/223 )
1414- Support for cell value validation according to data validation rules - @SailorMax [ #257 ] ( https://github.com/PHPOffice/PhpSpreadsheet/pull/257 )
15+ - Support for custom implementation, or configuration, of PDF libraries - @SailorMax [ #266 ] ( https://github.com/PHPOffice/PhpSpreadsheet/pull/266 )
1516
1617### Changed
1718
Original file line number Diff line number Diff line change @@ -779,6 +779,32 @@ Or you can instantiate directly the writer of your choice like so:
779779$writer = \P hpOffice\P hpSpreadsheet\W riter\P df\M pdf($spreadsheet);
780780```
781781
782+ #### Custom implementation or configuration
783+
784+ If you need a custom implementation, or custom configuration, of a supported
785+ PDF library. You can extends the PDF library, and the PDF writer like so:
786+
787+ ``` php
788+ class My_Custom_TCPDF extends TCPDF
789+ {
790+ // ...
791+ }
792+
793+ class My_Custom_TCPDF_Writer extends \P hpOffice\P hpSpreadsheet\W riter\P df\T cpdf
794+ {
795+ protected function createExternalWriterInstance ($orientation , $unit , $paperSize )
796+ {
797+ $instance = new My _Custom _TCPDF ($orientation , $unit , $paperSize );
798+
799+ // more configuration of $instance
800+
801+ return $instance ;
802+ }
803+ }
804+
805+ \P hpOffice\P hpSpreadsheet\I OFactory::registerWriter('Pdf', MY_TCPDF_WRITER::class);
806+ ```
807+
782808#### Writing a spreadsheet
783809
784810Once you have identified the Renderer that you wish to use for PDF
Original file line number Diff line number Diff line change 77
88class Dompdf extends Pdf
99{
10+ /**
11+ * Gets the implementation of external PDF library that should be used.
12+ *
13+ * @return \Dompdf\Dompdf implementation
14+ */
15+ protected function createExternalWriterInstance ()
16+ {
17+ return new \Dompdf \Dompdf ();
18+ }
19+
1020 /**
1121 * Save Spreadsheet to file.
1222 *
@@ -50,7 +60,7 @@ public function save($pFilename)
5060 }
5161
5262 // Create PDF
53- $ pdf = new \ Dompdf \ Dompdf ();
63+ $ pdf = $ this -> createExternalWriterInstance ();
5464 $ pdf ->setPaper (strtolower ($ paperSize ), $ orientation );
5565
5666 $ pdf ->loadHtml (
Original file line number Diff line number Diff line change 88
99class Mpdf extends Pdf
1010{
11+ /**
12+ * Gets the implementation of external PDF library that should be used.
13+ *
14+ * @param array $config Configuration array
15+ *
16+ * @return \Mpdf\Mpdf implementation
17+ */
18+ protected function createExternalWriterInstance ($ config )
19+ {
20+ return new \Mpdf \Mpdf ($ config );
21+ }
22+
1123 /**
1224 * Save Spreadsheet to file.
1325 *
@@ -54,7 +66,7 @@ public function save($pFilename)
5466
5567 // Create PDF
5668 $ config = ['tempDir ' => $ this ->tempDir ];
57- $ pdf = new \ Mpdf \ Mpdf ($ config );
69+ $ pdf = $ this -> createExternalWriterInstance ($ config );
5870 $ ortmp = $ orientation ;
5971 $ pdf ->_setPageSize (strtoupper ($ paperSize ), $ ortmp );
6072 $ pdf ->DefOrientation = $ orientation ;
Original file line number Diff line number Diff line change 77
88class Tcpdf extends Pdf
99{
10+ /**
11+ * Gets the implementation of external PDF library that should be used.
12+ *
13+ * @param string $orientation Page orientation
14+ * @param string $unit Unit measure
15+ * @param string $paperSize Paper size
16+ *
17+ * @return TCPDF implementation
18+ */
19+ protected function createExternalWriterInstance ($ orientation , $ unit , $ paperSize )
20+ {
21+ return new \TCPDF ($ orientation , $ unit , $ paperSize );
22+ }
23+
1024 /**
1125 * Save Spreadsheet to file.
1226 *
@@ -50,7 +64,7 @@ public function save($pFilename)
5064 }
5165
5266 // Create PDF
53- $ pdf = new \ TCPDF ($ orientation , 'pt ' , $ paperSize );
67+ $ pdf = $ this -> createExternalWriterInstance ($ orientation , 'pt ' , $ paperSize );
5468 $ pdf ->setFontSubsetting (false );
5569 // Set margins, converting inches to points (using 72 dpi)
5670 $ pdf ->SetMargins ($ printMargins ->getLeft () * 72 , $ printMargins ->getTop () * 72 , $ printMargins ->getRight () * 72 );
You can’t perform that action at this time.
0 commit comments