wkhtmltopdf add white space between content on every page - php

I am generating a PDF and it will create a white space between content.
example
When I output the same content just in HTML it will not, so I don't think it's the HTML or CSS; however, something on generating a PDF is creating that small gap, and I can't for the life of me figure it out.
I am hoping it's just a wkhtmltopdf setting, but I have been through all of them.
I am setting them in PHP like this:
return [
'page-size' => 'A4',
'page-height' => $height,
'page-width' => $width,
'dpi' => 96,
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'margin-bottom' => 0,
'disable-smart-shrinking' => true,
'load-media-error-handling' => 'abort'
];
I have added the page-size in an attempt to solve it, but it did not work.

Related

Mpdf - how to disable a fallback font when font-family is not available

I have a mPDF instance, in which I override the font directory and fontdata with an empty array .
What I want to achieve is that when I add HTML, which has a font-family that is not configured within my font arrays, an error is thrown. Now it automatically falls back on a font which is manually added.
mPDF instantiation
$config = [
'mode' => 'utf-8',
'format' => 'A4',
'author' => 'John Doe',
'creator' => 'John',
'default_font_size' => 12,
'default_font' => '',
'margin_left' => 0,
'margin_right' => 0,
'margin_top' => 0,
'margin_bottom' => 0,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'P',
'fontDir' => [], // Don't use fallback font dir.
'fontdata' => [], // Don't use fallback fontdata
$mpdf = new Mpdf($config);
Manually adding Roboto
$config['fontDir'] = array_merge($config['fontDir'], ['path/to/my/custom/roboto/font']
$config['fontdata'] = array_merge(config['fontdata'], [
'roboto' => [
'R' => 'Roboto-Regular.ttf',
],
];
Desired Result
The problem which occurs to me is that when I do the following:
$mpdf->WriteHTML('<body style="font-family: Lato">Hello world!</body>');
mPDf automatically uses my manually added Roboto as fallback font. But I would love to know if there is a way in which I can let mPDF throw an error in which it states that the font Lato is not configured within its font-data.
I really hope you guys can help me out!
Kind Regards.
This currently cannot be done with mPDF – it will always select a suitable substitution font as a browser would do.
The process of selecting a substitute is described in the documentation.

HTML lang attribute does not work in mPDF

I'm currently working on making the correct version of language dependent glyphs show up in their respective PDF files... From what I understand after reading through the mPDF documentation is that all I need to do is to set the the html lang value like below and to set autoScriptToLang and autoLangToFont to true
Example html where I want the Japanese version of the characters:
<html lang="ja">
<body>
Sample language-dependent glyphs: 直今令角雇
</body>
</html>
And yet it doesn't seem to reflect on the PDF file that is generated.
Here's the settings I'm passing over to Mpdf\Mpdf
$settings = [
'autoLangToFont' => true,
'autoScriptToLang' => true,
'format' => 'A4',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 20,
'margin_header' => 0,
'margin_footer' => 5,
'tempDir' => '/tmp/',
'default_font' => 'frutiger'
];
I tried displaying the HTML I'm passing over to mPDF and it works there, so I believe my issue is that I'm missing a setting to allow mPDF to display the Japanese versions of those characters.

Full line background color

I´m having a problem with phpword (https://phpword.readthedocs.io/en/latest/index.html)
I want to create a line where all the background is one color (100% width), but I can only make the background the size of the text.
$titleStyle=array('name' => 'Calibri','size' => 11, 'align' =>'center','marginTop' => 10,'bgColor' => 'd0cece');
// Create a new table style
$table_style = new \PhpOffice\PhpWord\Style\Table;
$table_style->setUnit(\PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT);
$table_style->setWidth(100 * 50);
$table_style->setBgColor('d0cece');
// Set up our table.
$tableTitle = $section->addTable($table_style);
$tableTitle->addRow();
$tableTitle->addCell()->addText('Identificação pessoal',$titleStyle);
Someone can help me?
I'm not really familiar with PhpWord, but have you tried to set width of a cell to 100% of document?
$titleStyle = array(
'name' => 'Calibri',
'size' => 11,
'align' =>'center',
'marginTop' => 10,
'bgColor' => 'd0cece',
'width' => 11905.51181102
);
From what I see in the docs, cell width needs to be provided in twip units, which after conversion from 210mm is 11905.51181102 (A4 page width)
https://www.translatorscafe.com/unit-converter/en/typography/1-3/twip-centimeter/

convert html to pdf in a4 size wkhtmltopdf

when convert html to pdf in wkhtmltopdf. My html works great on landscape view in pdf (wkhtmltopdf) but i want to a4 size pdf. In a4 size doesn't work properly table and other fields.
$options = array(
'page-size' => 'A4',
'no-outline', // option without argument
'encoding' => 'UTF-8', // option with argument
'user-style-sheet' => $cssPath,
'margin-top' => 0,
'margin-right' => 0,
'margin-bottom' => 0,
'margin-left' => 0,
);
pass this options and it will create a A4 pdf

QRCode position does not follow the results of previous output in php using library TCPDF

I have a problem with position of qrcode in tcpdf.
First, I want a output of qrcode like this:
but after I added many rows inside of table, qrcode position doesn't follow with my table, like a picture below.
And this is my code
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', 0, 143, 50, 30, $style, 'N');
Please help me, what must I do with this problem.
With gladness, I say thank you for your help.

Categories