PhpWord completely ignores cell style properties - symfony

PhpWord ignores the second argument of the the addCell() method completely when creating PDF or HTML Documents. I'm using symfony 3.5 and updated all libraries. PhpWord is currently at 0.14, dompdf at 0.8.2.
I'm trying to output them as PDF or HTML document, but none of them seem to use any of the array arguments.
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\ModProduct;
use AppBundle\Entity\ModProductsize;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\Style\Language;
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Shared\Html;
use PhpOffice\PhpWord\Style\Section;
use Symfony ...
public function listAction()
{
Settings::setPdfRenderer(Settings::PDF_RENDERER_DOMPDF, $this->get('kernel')->getProjectDir() . '/vendor/dompdf/dompdf/');
....
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$header1 = array('size' => 22, 'bold' => true, 'name' => 'Trebuchet MS');
$header2 = array('size' => 14, 'name' => 'Trebuchet MS');
$header3 = array('size' => 17, 'name' => 'Trebuchet MS');
$section->addText('Supplier Name', $header1); // STYLING WORKS
$table = $section->addTable();
$row = $table->addRow();
$w = array(
Converter::cmToTwip(7.4),
Converter::cmToTwip(2.8),
Converter::cmToTwip(2.6),
Converter::cmToTwip(1.5)
);
$fw = 0;
foreach($w as $value){
$fw += $value;
}
$row->addCell($w[0], ['bgColor' => '999999'])->addText('Produkt');
$row->addCell($w[1], $header2)->addText('ArtNr');
$row->addCell($w[2], ['align' => 'center'])->addText('EK-Preis');
$row->addCell($w[3])->addText('Bestm.');
}
Stlying for text works fine, but Cells are completely ignored. Tried bgColor, align, gridSpan, ... neither the PDF nor the HTML file change.

Related

Arial font looks different from HTML to a mpdf conversion

There must be something I don't know about how fonts work, a lot of things actually. May be someone can explain me why if the font in my css is set like "font-family: Arial, Helvetica, sans-serif;"
Why does it look a little different? In the pdf look stretched and rounder.
Are there different types of the same font? If that's the case how can I fix it?
HTML page:
PDF page:
This is what I'm applying to the html to print with mpdf
h1
{
text-align: center;
margin-top: 90px;
margin-bottom: 90px;
text-transform: uppercase;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 23vw;
}
$htmlStringView = view('pdf-view', ['content' => $content, 'cssString' => $cssString])->render();
$contract = $this->userContractRepository->show($id);
$mpdf = new Mpdf(['tempDir' => '/var/www/storage/temp', 'format' => [198, 280]]);
$contract = $this->addJsonDataToModelAttributes($contract);
$mpdf->SetHTMLFooter('<div style="text-align: right;">{PAGENO}/{nbpg}</div>');
$mpdf->WriteHTML($htmlStringView);
$mpdf->SetTitle($contract->title);
$mpdf->SetAuthor($contract->owner->email);
$mpdf->SetSubject(implode(", ", $contract->persons->pluck('full_name')->toArray()));
$mpdf->SetKeywords($id);
$mpdf->Output('/var/www/storage/app/' . $full_path);
Arial is not by default included in mPDF distribution, replacement is DejavuSans. If needed, you have to point your mPDF instance to the font file.
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'tempDir' => '/var/www/storage/temp',
'format' => [198, 280],
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/custom/font/directory',
]),
'fontdata' => $fontData + [
'arial' => [
'R' => 'arial.ttf',
'I' => 'arial-italic.ttf',
]
],
]);
see https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html

TYPO3 enable rte custom content element

how do I enable the Rich Text Editor for a custom content element in TYPO3 8.7?
I tried
$GLOBALS['TCA']['tt_content']['types']['myCustomElement'] = array('showitem' => '--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.general;
general,header,subheader,header_link,bodytext,
richtext:rte_transform[flag=rte_enabled|mode=ts_css],rte_enabled;
image,--div--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:tabs.appearance,--palette--;
LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.frames;
frames,--div--;
LLL:EXT:cms/locallang_ttc.xlf:tabs.access,--palette--;
LLL:EXT:cms/locallang_ttc.xlf:palette.visibility;
visibility,--palette--;
LLL:EXT:cms/locallang_ttc.xlf:palette.access;
access,--div--;
LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, categories, tx_gridelements_container, tx_gridelements_columns');
and
$GLOBALS['TCA']['tt_content']['types']['myCustomElement']['columnsOverrides']['bodytext']['defaultExtras'] = 'richtext[*]:rte_transform[mode=ts_css]';
in TCA/Overrides in my Extension. What am I missing?
I have improve your code and its work properly now
$myfield=[
'showitem' => '
--palette--; LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.general; general,header,subheader,header_link,bodytext,image,
--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:tabs.appearance,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.frames;frames,
--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access,
--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.visibility;visibility,
--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.access;access,
--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, categories, tx_gridelements_container, tx_gridelements_columns
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
];
And
$GLOBALS['TCA']['tt_content']['types']['myCustomElement']=$myfield;
May It will help you!!
The RTE in TYPO3 comes from an TYPO3-System-Extension called rte_ckeditor. Somehow I managed to deactivate it. After reactivating it I used the following in my TCA:
$GLOBALS['TCA']['tt_content']['types']['myCustomElement'] = array('showitem' =>'--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.general;general,header,subheader,header_link,bodytext,image,--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:tabs.appearance,--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.frames;frames,--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access,--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.visibility;visibility,--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.access;access,--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category, categories, tx_gridelements_container, tx_gridelements_columns');
$GLOBALS['TCA']['tt_content']['types']['myCustomElement']['columnsOverrides']['bodytext']['defaultExtras'] = 'richtext[*]:rte_transform[mode=ts_css]';

unable to set arial font in mpdf 7.x

followed the guide described here :
https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs, [__DIR__ . '/../../Resources/Public/Fonts',]),
'fontdata' => $fontData + [
'Arial' => [
'R' => 'arial.ttf',
'I' => 'arial.ttf',
]
],
'default_font' => 'Arial'
]);
$mpdf->WriteHTML($pdfTemplate->render());
$mpdf->Output(__DIR__.'/document.pdf','F');
in template have also inline style with font-family
font-family: Arial, sans-serif
but when i download pdf and inspect fonts they are in default DejaVuSansCondensed
is it bug or did i make mistake somewhere ?
long time ago, but i have the same problem.
solution was the uppcase key in "fontdata" (Arial). this should be lowercase (arial) and in css use: "font-family: arial, other-fallback-font"

How to add a link to an image in Remarkup (Phabricator)

When creating wiki pages in Phabricator's Phriction, I would like to use images as links. So rather than using a normal, textual link like
[[ url | this is a link]]
I would like to use an image for the link
[[ url | {F4711} ]]
Unfortunately, Phabricator renders just the text {F4711} and not the image from the file F4711.
Is this possible with Remarkup?
Any workarounds?
I don't think it is possible in Remarkup. The official documentation doesn't mention a way to do it and I've never seen it done, unfortunately.
Maybe you can use {img https://cdn-images-1.medium.com/fit/c/72/72/1*ZroWAkaLZdsNIBOHSoez3g.jpeg}
Syntax is as follows:
{image <IMAGE_URL>}
Parameters are also supported, like:
{image uri=<IMAGE_URI>, width=500px, height=200px, alt=picture of a moose, href=google.com}
URLs without a protocol are not supported.
see more: https://secure.phabricator.com/D16597
You can add a patch in https://github.com/phacility/phabricator/blob/master/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php#L169
like this:
$href = $file->getBestURI();
$sigil = 'lightboxable';
if (isset($options['href'])) {
$href = $options['href'];
$sigil = '';
}
$img = phutil_tag('img', $attrs);
$embed = javelin_tag(
'a',
array(
'href' => $href,
'class' => $image_class,
'sigil' => $sigil,
'meta' => array(
'phid' => $file->getPHID(),
'uri' => $file->getBestURI(),
'dUri' => $file->getDownloadURI(),
'viewable' => true,
'monogram' => $file->getMonogram(),
),
),
$img);
But in this case you cannot set the protocols:
{image uri=<IMAGE_URI>, width=500px, height=200px, alt=picture of a moose, href="//google.com"}
The reason is, phabricator renders first a a Tag with the url from the href attribiute and then the embed F Tag.

Set Background cell color in PHPExcel

How to set specific color to active cell when creating XLS document in PHPExcel?
$sheet->getStyle('A1')->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FF0000')
)
)
);
Source: http://bayu.freelancer.web.id/2010/07/16/phpexcel-advanced-read-write-excel-made-simple/
function cellColor($cells,$color){
global $objPHPExcel;
$objPHPExcel->getActiveSheet()->getStyle($cells)->getFill()->applyFromArray(array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array(
'rgb' => $color
)
));
}
cellColor('B5', 'F28A8C');
cellColor('G5', 'F28A8C');
cellColor('A7:I7', 'F28A8C');
cellColor('A17:I17', 'F28A8C');
cellColor('A30:Z30', 'F28A8C');
This code should work for you:
$PHPExcel->getActiveSheet()
->getStyle('A1')
->getFill()
->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->getStartColor()
->setRGB('FF0000')
But if you bother using this over and over again, I recommend using applyFromArray.
Seems like there's a bug with applyFromArray right now that won't accept color, but this worked for me:
$objPHPExcel
->getActiveSheet()
->getStyle('A1')
->getFill()
->getStartColor()
->setRGB('FF0000');
This always running!
$sheet->getActiveSheet()->getStyle('A1')->getFill()->getStartColor()->setRGB('FF0000');
Here is how you do it in PHPSpreadsheet, the newest version of PHPExcel
$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->applyFromArray([
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => [
'rgb' => 'FFDBE2F1',
]
],
]);
alternative approach:
$spreadsheet->getActiveSheet()
->getStyle('A1:F1')
->getFill()
->setFillType(Fill::FILL_SOLID)
->getStartColor()->setARGB('FFDBE2F1');
$objPHPExcel
->getActiveSheet()
->getStyle('A1')
->getFill()
->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->getStartColor()
->setRGB('colorcode'); //i.e,colorcode=D3D3D3
$objPHPExcel
->getActiveSheet()
->getStyle('A1')
->getFill()
->getStartColor()
->getRGB();
$objPHPExcel->getActiveSheet()->getStyle('B3:B7')->getFill()
->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->getStartColor()->setARGB('FFFF0000');
It's in the documentation, located here: https://github.com/PHPOffice/PHPExcel/wiki/User-Documentation-Overview-and-Quickstart-Guide
You can easily apply colours on cell and rows.
$sheet->cell(1, function($row)
{
$row->setBackground('#CCCCCC');
});
$sheet->row(1, ['Col 1', 'Col 2', 'Col 3']);
$sheet->row(1, function($row)
{
$row->setBackground('#CCCCCC');
});

Resources