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
Related
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.
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/
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.
We have a website that is currently on an Ubuntu 16.04 server and we are working on moving to Amazon. The rest of the site (Written in PHP Yii 1.1) is working fine except for the piece that present our reports in PDF format.
The report is written to pdf with no real issue but images show as a red X After some debugging I came to the conclusion that the majority of the images are png images and that is why they do not show. The single jpg image on the report is showing.
How can I get this to work? The html version of the report (that uses different code) gets the image from the same place and that works just fine. I cannot really convert all images because they are generated dynamically.
I read somewhere that pdf does not support png images, REALLY?? Why did it render just fine on the current server?
I do not believe that is is going to help but here is some code used:
main.config:
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)
),
),
Controller:
$mPDF1 = Yii::app()->ePdf->mpdf('utf-8', 'A4');
$mPDF1->simpleTables = true;
$mPDF1->useSubstitutions = false;
$mPDF1->WriteHTML($this->renderPartial('pdfRXMapFile', array('model' => $model)));
I'm trying to create a TextBox without a border in PHPWord, but setting borderColor or borderSize to 0 or null has no effect and I always get at least a black border around the text box.
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$textbox = $section->addTextBox(
array(
'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END,
'width' => 200,
'height' => 40,
'borderColor' => null,
'borderSize' => 0,
)
);
$textbox->addText('dummy-text ...', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord);
$objWriter->save('dummy.docx');
To create a borderbox without border you can use (git issue: no outline textbox):
'borderSize' => 'none'
Tested and working with PhpWord 0.13.0 & opening the generated document with MsWord (libreoffice didn't seem to recognize this setting)
If anyone is still looking for an answer in PHPWord 0.17 following solution works:
'borderColor' => 'none'