laravel-pdf
laravel-pdf copied to clipboard
dpi & dpi_img params don't work
When i change dpi and dpi_img in config array, pdf not change.
$pdf = PDF::loadView('pdf.product', ['html' => $html], [], [
"dpi" => 300,
"img_dpi" => 300,
"format" => "A5",
"orientation" => "P",
"display_mode" => "fullpage",
"zoom_builder" => 80,
"height_in_pixel" => 761.0,
"width_in_pixel" => 539.0
]);
$content = $pdf->output();
I tested with mpdf and its worked.
$html = view('pdf.product')->with('html', $html)->render();
$config = array_merge(config('mpdf'), [
"dpi" => 300,
"img_dpi" => 300,
"format" => "A5",
"orientation" => "P",
"display_mode" => "fullpage",
"zoom_builder" => 80,
"height_in_pixel" => 761.0,
"width_in_pixel" => 539.0
]);
$pdf = new Mpdf($config);
$pdf->WriteHTML($html);
And i saw, in niklasravnsborg\LaravelPdf\PDF construct, $mpdf_config have not dpi & dpi_img key
public function __construct($html = '', $config = [])
{
$this->config = $config;
// @see https://mpdf.github.io/reference/mpdf-functions/construct.html
$mpdf_config = [
'mode' => $this->getConfig('mode'), // Mode of the document.
'format' => $this->getConfig('format'), // Can be specified either as a pre-defined page size, or as an array of width and height in millimetres
'default_font_size' => $this->getConfig('default_font_size'), // Sets the default document font size in points (pt).
'default_font' => $this->getConfig('default_font'), // Sets the default font-family for the new document.
'margin_left' => $this->getConfig('margin_left'), // Set the page margins for the new document.
'margin_right' => $this->getConfig('margin_right'), // Set the page margins for the new document.
'margin_top' => $this->getConfig('margin_top'), // Set the page margins for the new document.
'margin_bottom' => $this->getConfig('margin_bottom'), // Set the page margins for the new document.
'margin_header' => $this->getConfig('margin_header'), // Set the page margins for the new document.
'margin_footer' => $this->getConfig('margin_footer'), // Set the page margins for the new document.
'orientation' => $this->getConfig('orientation'), // This attribute specifies the default page orientation of the new document if format is defined as an array. This value will be ignored if format is a string value.
'tempDir' => $this->getConfig('tempDir') // temporary directory
];
// Handle custom fonts
$mpdf_config = $this->addCustomFontsConfig($mpdf_config);
$this->mpdf = new Mpdf\Mpdf($mpdf_config);
// If you want to change your document title,
// please use the <title> tag.
$this->mpdf->SetTitle('Document');
$this->mpdf->SetAuthor ( $this->getConfig('author') );
$this->mpdf->SetCreator ( $this->getConfig('creator') );
$this->mpdf->SetSubject ( $this->getConfig('subject') );
$this->mpdf->SetKeywords ( $this->getConfig('keywords') );
$this->mpdf->SetDisplayMode ( $this->getConfig('display_mode') );
if (isset($this->config['instanceConfigurator']) && is_callable(($this->config['instanceConfigurator']))) {
$this->config['instanceConfigurator']($this->mpdf);
}
$this->mpdf->WriteHTML($html);
}
@KevinLbr I expect the package doesn't take all the configuration we pass it just takes what it needs only
$mpdf_config = [
'mode' => $this->getConfig('mode'), // Mode of the document.
'format' => $this->getConfig('format'), // Can be specified either as a pre-defined page size, or as an array of width and height in millimetres
'default_font_size' => $this->getConfig('default_font_size'), // Sets the default document font size in points (pt).
'default_font' => $this->getConfig('default_font'), // Sets the default font-family for the new document.
'margin_left' => $this->getConfig('margin_left'), // Set the page margins for the new document.
'margin_right' => $this->getConfig('margin_right'), // Set the page margins for the new document.
'margin_top' => $this->getConfig('margin_top'), // Set the page margins for the new document.
'margin_bottom' => $this->getConfig('margin_bottom'), // Set the page margins for the new document.
'margin_header' => $this->getConfig('margin_header'), // Set the page margins for the new document.
'margin_footer' => $this->getConfig('margin_footer'), // Set the page margins for the new document.
'orientation' => $this->getConfig('orientation'), // This attribute specifies the default page orientation of the new document if format is defined as an array. This value will be ignored if format is a string value.
'tempDir' => $this->getConfig('tempDir') // temporary directory
];
And pass them to mpdf.