Replies: 1 comment
-
Hi @georak I think that in blade files you can use eg: class YourDocumentViewPresenter
{
public Collection $pages;
public function __construct($text)
{
$linesArray = explode("\n", $text);
$linesCollection = collect($linesArray);
$this->pages = $linesCollection->chunk(4);
}
} In your controller you should be able to use the view presenter like this: $text = "This is the first line.\nThis is the second line.\nAnd here goes the third line.";
$content = new YourDocumentViewPresenter($text);
return pdf('your-pdf', $content->pages); Then in your blade file you should be able to do something like: @foreach($pages as $page)
@if($loop->index % 4 == 0)
@pageBreak
@endif
{{ $page }}
@endforeach With this code you are using a view presenter to transform a text into a collection and then chunk it by groups of 4 (to set a paragraphs that looks like a safe amount of text per paragraph). Then it loops in a blade file and as the paragraphs used are 4 per page (a safe number of paragraphs per page) you can print the directive to page break if the loop index residual of 4 is equal to zero. Take in mindYou can go a little bit further and check the amount of strings per line or per paragraph in the view presenter, I just set a good example but you can set it as granular as you need. Hope it helps |
Beta Was this translation helpful? Give feedback.
-
Hello all,
I have one div with dynamic content which may need more than 1 page to be displayed. Is there any way to add margin top on the second page only (without using ->margins())
Beta Was this translation helpful? Give feedback.
All reactions