Create TextBox without a border in PHPWord - php

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'

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.

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/

wkhtmltopdf add white space between content on every page

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.

how to set strikethrough effects for cell with Maatwebsite/Laravel-Excel?

I'm using Maatwebsite/Laravel-Excel to export xlsx file.
How to set strikethrough for cell like image
I have read document but can't resolve.
My code (not work):
$sheet->cells("I5", function($cells) {
$cells->setFont(array(
// 'underline' => true
'strikethrough'=>true
));
});
Thank!
According to documentation, you can style your Cell or Stylesheet (https://laravel-excel.maatwebsite.nl/2.1/blade/styling.html) :
// Set font with ->setStyle()`
$sheet->setStyle(array(
'font' => array(
'name' => 'Calibri',
'size' => 12,
'bold' => true,
'strikethrough' => true,
)
));
It uses PhpOffice / Spreadsheet, so look the doc of this plugin : https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/

PHPWord - how to add horizontal line to docx/odt document

I'd started to use PHPWord to generate DOCX/ODT from my PHP application.
While it mostly works "out of the box" for me, there is an issue, while trying to add "Horizontal line" to my generated document.
This code just adds nothing, and I can't figure out what's the problem:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addLine(array('dash' => 'dash', 'width' => 100, 'height' => 2, 'weight' => 10));
$phpWord->save(wp_upload_dir()['basedir'].'/test.odt', 'ODText'); // it won't display horizontal line in DOCX either
Thanks for help

Categories