I have been working with Laravel Snappy (https://github.com/barryvdh/laravel-snappy) for PDF generation.
After applying a combination of settings (word break applied), Snappy PDF takes 108 characters per line with Mono-space font "Roboto Mono". However, when I add two different text strings with same number of characters, Snappy prints one string with 108 characters in same line and other string with 108 characters in two lines.
Strings used
String 1:
governments but it was ineffectual at providing stability as it could not collect taxes and had no executive (108 characters)
String 2:
century away from more densely populated lifestyles and towards reorganized polities elsewhere. The European (108 characters)
Following style and html are as follows:
text_message.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,500;1,600;1,700&display=swap" rel="stylesheet">
<style type="text/css">
* {
overflow: visible !important;
font-family: 'Roboto Mono', monospace;
}
@page {
size: letter;
margin: 0;
padding: 0 !important;
}
html body {
min-width: initial !important;
font-family: 'Roboto Mono', monospace;
margin: 0 !important;
padding: 0 !important;
}
.text-message {
font-size: 14px;
font-style: normal;
line-height: 21px;
letter-spacing: 0.045em;
}
</style>
</head>
<body class="letter">
<section class="sheet break-after" style="position: relative;">
<div class="text-message" style="word-break: break-word;">
{!! nl2br($order->textMessage->message) !!}
</div>
</section>
</body>
</html>
For Laravel Snappy has following settings:
GeneratePdf.php Service class
$order = Order::find(200);
$pdf = SnappyPdf::setOption('enable-javascript', true);
$pdf->setOption('footer-font-size','8');
$pdf->setOption('footer-right', 'page [page] of [topage]');
$pdf->setOption('margin-top', 8);
$pdf->setOption('margin-bottom', 8);
$pdf->setOption('margin-left', '5');
$pdf->setOption('margin-right', '5');
$pdf->setOption('page-offset', '-2');
Storage::put('path/to/file', $pdf->getOutputFromHtml(view('text_message', compact('order'))));
Output by Snappy:
PDF link: order_pdf.pdf
I need exactly same number of characters in every line as pricing depends on it. Can someone tell me why is it printing same number of characters in two different ways?
I added long string text to check how many characters Snappy takes in with the above style and font. I used that number of characters with two different strings. As it has mono space font, it should print both strings in single line and it should not break string 1 into two lines.