How to output PDF by HTML with CSS in Laravel project - laravel

I am looking for a way to create PDF from (BLADE )HTML with CSS
I am using this.
"barryvdh/laravel-dompdf": "^0.8.7",
but its output looks misconversion.
$pdf = PDF::loadView('test'
)->setPaper('a4', 'portrait');
return $pdf->stream("aaa.pdf");
I use this html
https://github.com/okoppe8/PaperFormToHTML
result here.

Use Custom font to display.So download simhei.ttf from any source.and place it public folder.Then you can use below css
<style type="text/css">
#font-face {
font-family: SimHei;
src: url('simhei.ttf') format('truetype');
}
* {
font-family: SimHei;
}
</style>
As per github issue
Ref:https://github.com/barryvdh/laravel-dompdf/issues/198
Download font from
https://www.wfonts.com/font/simhei

Related

How to load custom fonts instantly next js and prevent FOUT

I have a next JS application and my custom fonts are in my public folder.
My task is to prevent FOUT (flash of unstyled text) on site load and so I have settled for using font-display:block;
#font-face {
font-family: 'Proxima Nova';
src: url('/fonts/ProximaNova-Regular.woff2') format('woff2'),
url('/fonts/ProximaNova-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
font-display:block;
}
in document.tsx I am preloading the fonts in the Head component as such :
<link
rel="preload"
href="/fonts/ProximaNova-Bold.woff2"
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
in _app.tsx I am importing global styles as such import './styles.css';
When i check load time for my fonts in the nextwork tab, it is roughly 3 seconds (please refer to screenshot).
Any suggestions on making my font load faster?

Ugly Arial font rendering with wkhtmltopdf.exe

Looking af https://wkhtmltopdf.org to render HTML to PDF
What can be done to improve the horrific rendering of a standard font link Arial?
HTML
<div style="font-family:'Arial'; font-size:11px; font-weight:100;">THIS is my test size:11 weight:100</div>
Command line
PS C:\Users\me\test> echo "<div style=""font-family:'Arial'; font-size:11px; font-weight:100; "">THIS is my test size:11 weight:100</div>" | .\wkhtmltopdf.exe - test.pdf
Rendered result
Expected result
I had a similar issue with a webfont (which was not installed by default in the system). I could only solve it including the base64 font in the style.css passed to user-style-sheet. Reference here
#font-face {
font-family: 'Arial';
font-style: normal;
font-weight: 400;
src: url(data:font/opentype;charset=utf-8;base64,d09GRgABAAAAAD00AA4A---[large string ommited]----3MAuAH/hbAEjQA=) format("woff"),
url(data:font/truetype;charset=utf-8;base64,AAEAAAARAQAABAAQRFNJRwAAAAEAAJUIAAA---[large string ommited]-----wAAAAAAAAAAAAEAAAAA) format("truetype");
}
You can use a tool like this to transform your font to base64.
Hope it helps!

Using Japanese characters in DOMPDF?

I'm trying to get my PDF's created using DOMpdf to work correctly with Japanese characters. I have it working fine with French etc, but Japanese characters don't show (just get ???)
Here is how the HTML page looks:
...but the PDF comes out as:
The code I'm using is pretty simple:
<?php
// include autoloader
require_once '/path/to/admin/invoices/autoload.inc.php';
define("DOMPDF_ENABLE_REMOTE", true);
define("DOMPDF_UNICODE_ENABLED", true);
// reference the Dompdf namespace
use Dompdf\Dompdf;
$order_id = $argv[1];
$content = file_get_contents("/path/to/admin/invoices/html_versions/$order_id.html");
// // instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($content);
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
From what I can see, it wants a font specifically for Japanese.
What font would work?
Can I have it running alongside the normal font? i.e I still want to be able to show stuff like íóé etc
UPDATE: I'm getting a bit closer!
I've downloaded the CyberCJK TTF font (as suggested here: https://github.com/dompdf/dompdf/issues/938 )
Then I tweaked my CSS to:
#font-face {
font-family: CyberCJK;
font-style: normal;
font-weight: normal;
src: url("https://example.com/cgi-bin/admin/invoices/lib/fonts/DejaVuSerif.ttf") format("truetype");
}
* {
font-family: 'CyberCJK', sans-serif;
}
#page { margin: 0px; } body { margin: 0px; }
html { font-size: 14px/1; font-family: 'CyberCJK', sans-serif; overflow: auto; }
..and now I get partial characters:
I have also tested uploading my HTML page on: http://www.htm2pdf.co.uk , and it comes out perfectly as a PDF, and is also only 64kb, compared to 13mb+ using DOMPdf. Something must be up!
I'm really at a loss as to what else to try :/

Buttons not showing correctly (Videojs font not working on subdomain)

I'm having problems with video.js. On the main domain everthings works fine. But on the www. subdomain the buttons are not showing correctly (It's just showing ).
It looks like the font doesn't work on the subdomain. Any ideas to fix this?
VideoJS uses a custom font, defined using the #font-face directive in video-js.css. The paths defined inside are relative. When FireFox goes to load the fonts, it uses the root URL of the CSS file and concatenates the font paths.
The custom fonts are thus being loaded from your main domain when viewing the subdomain. Doesn't sound like a problem, right? But Firefox does not allow cross-domain fonts without access control headers for security.
In other words, FireFox normally requires every custom font to be loaded from the domain of the page that's showing. If you're viewing www.example.com, your fonts have to come from www.example.com, not example.com.
You can either
Use the solution linked above to add the appropriate headers to your server (if you have control) to allow the "cross-domain" fonts (www.example.com is considered a different domain from example.com)
Load the VideoJS CSS file dynamically from whichever domain is active.
If you want to go the latter route, when the user's viewing www.example.com, load http://*www.*example.com/path/to/video-js/video-js.min.css. When viewing example.com, load http://example.com/path/to/video-js/video-js.min.css.
Note that Webkit doesn't care -- seems to just be a Firefox problem.
Apply this css and get output
#font-face {
font-family: 'VideoJS';
src: url('https://vjs.zencdn.net/f/1/vjs.eot');
src: url('https://vjs.zencdn.net/f/1/vjs.eot?#iefix') format('embedded-opentype'),
url('https://vjs.zencdn.net/f/1/vjs.woff') format('woff'),
url('https://vjs.zencdn.net/f/1/vjs.ttf') format('truetype');
}
.video-js .vjs-play-control.vjs-playing .vjs-icon-placeholder:before, .vjs-icon-pause:before {
content: "\f103";
font-family: 'VideoJS';
}
.video-js .vjs-mute-control .vjs-icon-placeholder:before, .vjs-icon-volume-high:before {
content: "\f107";
font-family: 'VideoJS';
}
.video-js .vjs-big-play-button .vjs-icon-placeholder:before, .video-js .vjs-play-control .vjs-icon-placeholder:before, .vjs-icon-play:before {
content: "\f101";
font-family: 'VideoJS';
}
.video-js .vjs-picture-in-picture-control .vjs-icon-placeholder:before, .vjs-icon-picture-in-picture-enter:before {
content: "\f121";
font-family: 'VideoJS';
}
.video-js .vjs-fullscreen-control .vjs-icon-placeholder:before, .vjs-icon-fullscreen-enter:before {
content: "\f108";
font-family: 'VideoJS';
}
This solution worked for me when the icons were rendering blank:
#font-face {
font-family: VideoJS;
src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAABDkAAsAAAAAG6gAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADsAAABUIIslek9TLzIAAAFEAAAAPgAAAFZRiV3hY21hcAAAAYQAAADaAAADPv749/pnbHlmAAACYAAAC3AAABHQZg6OcWhlYWQAAA3QAAAAKwAAADYZw251aGhlYQAADfwAAAAdAAAAJA+RCLFobXR4AAAOHAAAABMAAACM744AAGxvY2EAAA4wAAAASAAAAEhF6kqubWF4cAAADngAAAAfAAAAIAE0AIFuYW1lAAAOmAAAASUAAAIK1cf1oHBvc3QAAA/AAAABJAAAAdPExYuNeJxjYGRgYOBiMGCwY2BycfMJYeDLSSzJY5BiYGGAAJA8MpsxJzM9kYEDxgPKsYBpDiBmg4gCACY7BUgAeJxjYGS7wTiBgZWBgaWQ5RkDA8MvCM0cwxDOeI6BgYmBlZkBKwhIc01hcPjI+FGJHcRdyA4RZgQRADK3CxEAAHic7dFZbsMgAEXRS0ycyZnnOeG7y+qC8pU1dHusIOXxuoxaOlwZYWQB0Aea4quIEN4E9LzKbKjzDeM6H/mua6Lmc/p8yhg0lvdYx15ZG8uOLQOGjMp3EzqmzJizYMmKNRu27Nhz4MiJMxeu3Ljz4Ekqm7T8P52G8PP3lnTOVk++Z6iN6QZzNN1F7ptuN7eGOjDUoaGODHVsuvU8MdTO9Hd5aqgzQ50b6sJQl4a6MtS1oW4MdWuoO0PdG+rBUI+GejLUs6FeDPVqqDdDvRvqw1CfhpqM9At0iFLaAAB4nJ1YDXBTVRZ+5/22TUlJ8we0pHlJm7RJf5O8F2j6EymlSPkpxaL8U2xpa3DKj0CBhc2IW4eWKSokIoLsuMqssM64f+jA4HSdWXXXscBq67IOs3FXZ1ZYWVyRFdo899yXtIBQZ90k7717zz3v3HPPOfd854YCCj9cL9dL0RQFOqCbGJnrHb5EayiKIWN8iA/hWBblo6hUWm8TtCDwE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pcAMs9Yu6AK9caF76zoLWIWcfMGOSkVduvSWechqZsz040Ib2PY3urxBJTzriT95lipz+TN1fmAAAAeJxtkMl2wjAMRfOAhABlKm2h80C3+ajgCKKDY6cegP59TYBzukAL+z1Zsq8ctaJTTKPrsUQLbXQQI0EXKXroY4AbDDHCGBNMcYsZ7nCPB8yxwCOe8IwXvOIN7/jAJ76wxHfUqWX+OzgumWAjJMV17i0Ndlr6irLKO+qftdT7i6y4uFSUvCknay+lFYZIZaQcmfH/xIFdYn98bqhra1aKTM/6lWMnyaYirx1rFUQZFBkb2zJUtoXeJCeg0WnLtHeSFc3OtrnozNwqi0TkSpBMDB1nSde5oJXW23hTS2/T0LilglXX7dmFVxLnq5U0vYATHFk3zX3BOisoQHNDFDeZnqKDy9hRNawN7Vh727hFzcJ5c8TILrKZfH7tIPxAFP0BpLeJPA==) format("woff");
font-weight: normal;
font-style: normal;
}

CK-editor, autoset styles in dropdown with custom.css

I'm having trouble with CK4 and getting the styles for headers reflected in the styles-dropdown.
The .css should be shared of both back- and frontend and uses #page as css-id
Is there any way to tell the dropdown to parse headers with the #page-prefix.
I'm using
CKEDITOR.config.bodyId = 'page';
and css
.cke_editable {
}
#page {
/* works - editor area goes black..
font-family:Arial;
margin:10px;
font-family:Arial;
background-color:#000;
font-size: 10px;
color:#fff;
}
#page h1 {
/* works in editor-area, but not dropdown */
font-family: Verdana;
color:#999;
}
.cke_editable h2 {
/* same as h1.. */
font-family:Arial;
color:#f00;
font-size:16px;
background-color:#999;
}
h3 {
/* work BOTH in editor and style shows in dropdown. */
color:#0f0;
}
I guess that you're about to use stylesheetparser plugin to parse additional selectors. This issue has already been answered here: CKEditor - Stylesheet Parser - Valid Selectors
It's not straightforward but I believe you'll manage to do this. Good luck!
The problem is that CKEditor doesn't apply the bodyId and/or bodyClass to the styles combo: http://dev.ckeditor.com/ticket/7452
As you can see that bug was reported almost two years ago and it has been without activity from the developers most of that time.
I achived a working solution by parsing the css e.g.
#page h1 {...}
when attaching to CK like:
['config']['css'] = 'parseMyCss.php?theFile=style.css
and in parseMyCss (simplified):
$s = file_get_contents($theFile);
$s = str_replace('#page ','', $s);
header('content-type:text/css');
echo $s;

Resources