mpdf set font arial not working - mpdf

I am using mpdf 6.0 to create PDF from a html form.
I want to use Arial font. In my css file there is:
font-family:Arial, Helvetica, sans-serif;
in Mpdf in the "config_fonts.php" file I have activated the font directory:
define("_MPDF_SYSTEM_TTFONTS", 'C:/Windows/Fonts/');
then;
$this->backupSubsFont = array('arial','dejavusanscondensed','freeserif');
and;
$this->fonttrans = array(
'arial' => 'arial',
'times' => 'timesnewroman',
'courier' => 'couriernew',
'trebuchet' => 'trebuchetms',
'comic' => 'comicsansms',
'franklin' => 'franklingothicbook',
'ocr-b' => 'ocrb',
'ocr-b10bt' => 'ocrb',
'damase' => 'mph2bdamase');
But anyway the PDF file which is produced contains always the font
dejavu sans condensed and not arial.
any ideas?
thanks a lot.
regards
hawk

Download and move the Arial font TTF into the ttfonts folder and declare it manually in config_fonts.php.

This work for me:
$mpdf = new \Mpdf\Mpdf(['default_font' => 'arial']);
You can read more in the documentation:
https://mpdf.github.io/fonts-languages/default-font.html

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

Registered fontawesome icons are not shown within the pagetree

In ext_tables.php I register a fontawesome icon for a new pageDocType.
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)
->registerIcon(
'apps-pagetree-igstory',
\TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider::class,
[
'name' => 'book',
'spinning' => false
]
);
The Icon is correctly shown in the drag-and-drop area above the page-tree.
But within the page-tree the icon isn't available.
If I use an SVG-Icon and integrate it with the SvgIconProvider, it works also in the page-tree.
it looks like this is not supported by the page-tree in TYPO3 9
https://forge.typo3.org/issues/83468

PhpWord completely ignores cell style properties

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.

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"

wicked_pdf (with wkhtmltopdf) doesn’t render Font Awesome icons

I’m trying to convert an existing html document with Font Awesome icons included in pdf. I use wicked_pdf for this task. But obviously is creating a pdf some very hard task.
All Font Awesome Icons are replaced with blanks. I need some advise to make things work.
My configuration:
wicked_pdf (1.1.0)
wkhtmltopdf-binary-edge (0.12.4.0)
The generated html looks like this:
<p>
<i class="fa fa-phone"></i> +49 123 4567890
</p>
The controller action for creating the pdf:
def create_pdf
#presenter = PortfolioPDFPresenter.new(#portfolio, self)
html = render_to_string(template: 'portfolios/pdf_templates/portfolio',
layout: 'pdf_layout')
footer_html = render_to_string(template: 'portfolios/pdf_templates/footer',
layout: 'pdf_layout')
title = ActionView::Base.full_sanitizer.sanitize(#portfolio.heading.html_safe, tags: [])
pdf = WickedPdf.new.pdf_from_string(html,
title: title,
author: current_user.fullname,
page_size: 'A4',
margin: { top: 20, bottom: 40 },
print_media_type: true,
dpi: 600,
zoom: 1,
no_pdf_compression: false,
lowquality: false,
outline: { outline: true, outline_depth: 4 },
footer: { content: footer_html },
extra: '--encoding UTF8 --disable-smart-shrinking')
send_data(pdf,
filename: "#{t('activerecord.models.portfolio.one')}-#{current_user.fullname}.pdf",
disposition: 'attachment',
type: :pdf)
end # create_pdf
And finally the layout:
!!!
%html{lang: "#{I18n.locale.to_s}"}
%head
%meta{ content: 'text/html; charset=UTF-8', 'http-equiv': 'Content-Type' }
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no' }
%meta{ 'http-equiv': 'Accept-CH', content: 'DPR, Viewport-Width, Width' }
%title
= t('app_title')
= csrf_meta_tags
= stylesheet_link_tag 'https://fonts.googleapis.com/css?family=Exo+2:400,700'
= stylesheet_link_tag wicked_pdf_asset_base64("pdf_styles"), media: 'print'
= stylesheet_link_tag wicked_pdf_asset_base64("pdf_styles")
= stylesheet_link_tag 'http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'
%body
#main-content
= yield
Faced a similar issue myself. First I wasn't getting any icons and then subsequently, I started getting a weird W-on-top-of-M kind of icon.
Not getting any icons
Was resolved once I added the absolute CDN path to Font awesome to my pdf layout file.
https://github.com/brunzino/wpdf-icon-debug/pull/1/files?diff=split
Getting a weird W-on-top-of-M icon
This wasn't a problem on the server (Ubuntu 16.04). As in, the icon showed correctly on the production site. However on my Mac all icons were replaced by this strange icon. Never really resolved it but read somewhere that this gets resolved by installing the ttf font on the Mac.
Hope this helps

Resources