// dompdf requires dimensions in points
$paper_size = [0, 0, $paper_width, $paper_height];
$orientation = CRM_Core_BAO_PdfFormat::getValue('orientation', $format);
+
+ if (\Civi::settings()->get('weasyprint_path')) {
+ if ($orientation == 'landscape') {
+ $css_pdf_width = $paperSize['height'];
+ $css_pdf_height = $paperSize['width'];
+ }
+ else {
+ $css_pdf_width = $paperSize['width'];
+ $css_pdf_height = $paperSize['height'];
+ }
+ $css_page_size = " size: {$css_pdf_width}{$paperSize['metric']} {$css_pdf_height}{$paperSize['metric']};";
+ }
+ else {
+ $css_page_size = "";
+ }
+
$metric = CRM_Core_BAO_PdfFormat::getValue('metric', $format);
$t = CRM_Core_BAO_PdfFormat::getValue('margin_top', $format);
$r = CRM_Core_BAO_PdfFormat::getValue('margin_right', $format);
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
- <style>@page { margin: {$t}{$metric} {$r}{$metric} {$b}{$metric} {$l}{$metric}; }</style>
+ <style>@page { margin: {$t}{$metric} {$r}{$metric} {$b}{$metric} {$l}{$metric};$css_page_size }</style>
<style type=\"text/css\">@import url(" . CRM_Core_Config::singleton()->userFrameworkResourceURL . "css/print.css);</style>
{$htmlHeader}
</head>
</body>
</html>";
if (\Civi::settings()->get('weasyprint_path')) {
- return self::_html2pdf_weasyprint($paper_size, $orientation, $margins, $html, $output, $fileName);
+ return self::_html2pdf_weasyprint($html, $output, $fileName);
}
elseif (\Civi::settings()->get('wkhtmltopdfPath')) {
return self::_html2pdf_wkhtmltopdf($paper_size, $orientation, $margins, $html, $output, $fileName);
}
/**
- * @param float|int[] $paper_size
- * @param string $orientation
- * @param array $margins
* @param string $html
* @param bool $output
* @param string $fileName
*/
- public static function _html2pdf_weasyprint($paper_size, $orientation, $margins, $html, $output, $fileName) {
+ public static function _html2pdf_weasyprint($html, $output, $fileName) {
$weasyprint = new Pontedilana\PhpWeasyPrint\Pdf(\Civi::settings()->get('weasyprint_path'));
- $weasyprint->setOption("page-width", $paper_size[2] . "pt");
- $weasyprint->setOption("page-height", $paper_size[3] . "pt");
- $weasyprint->setOption("orientation", $orientation);
- $weasyprint->setOption("margin-top", $margins[1] . $margins[0]);
- $weasyprint->setOption("margin-right", $margins[2] . $margins[0]);
- $weasyprint->setOption("margin-bottom", $margins[3] . $margins[0]);
- $weasyprint->setOption("margin-left", $margins[4] . $margins[0]);
$pdf = $weasyprint->getOutputFromHtml($html);
if ($output) {
return $pdf;