Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to use customized pdf library #266

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

class Dompdf extends Pdf implements IWriter
{
/**
* Gets the implementation of external PDF library that should be used.
*
* @param array $config Configuration array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no parameter named $config.

*
* @return Dompdf implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be \Dompdf\Dompdf, not Dompdf

*/
protected function getExternalWriter()
{
return new \Dompdf\Dompdf();
}

/**
* Save Spreadsheet to file.
*
Expand Down Expand Up @@ -51,7 +63,7 @@ public function save($pFilename)
}

// Create PDF
$pdf = new \Dompdf\Dompdf();
$pdf = $this->getExternalWriter();
$pdf->setPaper(strtolower($paperSize), $orientation);

$pdf->loadHtml(
Expand Down
14 changes: 13 additions & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

class Mpdf extends Pdf implements IWriter
{
/**
* Gets the implementation of external PDF library that should be used.
*
* @param array $config Configuration array
*
* @return Mpdf implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be \Mpdf\Mpdf not Mpdf

*/
protected function getExternalWriter($config)
{
return new \Mpdf\Mpdf($config);
}

/**
* Save Spreadsheet to file.
*
Expand Down Expand Up @@ -55,7 +67,7 @@ public function save($pFilename)

// Create PDF
$config = ['tempDir' => $this->tempDir];
$pdf = new \Mpdf\Mpdf($config);
$pdf = $this->getExternalWriter($config);
$ortmp = $orientation;
$pdf->_setPageSize(strtoupper($paperSize), $ortmp);
$pdf->DefOrientation = $orientation;
Expand Down
16 changes: 15 additions & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

class Tcpdf extends Pdf implements IWriter
{
/**
* Gets the implementation of external PDF library that should be used.
*
* @param string $orientation Page orientation
* @param string $unit Unit measure
* @param string $paperSize Paper size
*
* @return TCPDF implementation
*/
protected function getExternalWriter($orientation, $unit, $paperSize)
{
return new \TCPDF($orientation, $unit, $paperSize);
}

/**
* Save Spreadsheet to file.
*
Expand Down Expand Up @@ -51,7 +65,7 @@ public function save($pFilename)
}

// Create PDF
$pdf = new \TCPDF($orientation, 'pt', $paperSize);
$pdf = $this->getExternalWriter($orientation, 'pt', $paperSize);
$pdf->setFontSubsetting(false);
// Set margins, converting inches to points (using 72 dpi)
$pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
Expand Down