Hey there.
I tried different way’s - but none of them work.
I want after $site->createChild() that it create on the fly a pdf file.
I got all my code in a controller.
If i just post in my template <h1>Test<h1>
- Works.
Is maybe render to “much”? is there a better way?
Finally what I want is, that after the child is create load html of it and make pdf
Way 1 - endless loading after create (over form - frontend)
try {
$projectName = $data["projectName"];
$projectSlug = str::slug($data["projectName"]."-".date("d.m.Y, h:i"));
$posts = $site->createChild([
"slug" => $projectSlug ,
"template" => "posts",
"content" => $data
]);
$postsDirectory = $posts->contentFileDirectory();
if ($posts) {
$mpdf = new \Mpdf\Mpdf();
ob_start();
echo $posts->render();
$html = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML($html);
$mpdf->Output( $postsDirectory .'/'. $projectName .'.pdf', \Mpdf\Output\Destination::FILE);
}
Way 2 - endless loading after create (over form - frontend)
try {
$projectName = $data["projectName"];
$projectSlug = str::slug($data["projectName"]."-".date("d.m.Y, h:i"));
$posts = $site->createChild([
"slug" => $projectSlug ,
"template" => "posts",
"content" => $data
]);
$postsDirectory = $posts->contentFileDirectory();
if ($posts) {
$mpdf = new \Mpdf\Mpdf();
ob_start();
$kirby->impersonate('kirby', function () use($posts) {
echo $posts->render();
return;
});
$html = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML($html);
$mpdf->Output( $postsDirectory .'/'. $projectName .'.pdf', \Mpdf\Output\Destination::FILE);
}
Way 3 - endless loading after create (over form - frontend)
try {
$projectName = $data["projectName"];
$projectSlug = str::slug($data["projectName"]."-".date("d.m.Y, h:i"));
$posts = $site->createChild([
"slug" => $projectSlug ,
"template" => "posts",
"content" => $data
]);
$postsDirectory = $posts->contentFileDirectory();
if ($posts) {
$mpdf = new \Mpdf\Mpdf();
ob_start();
$content = file_get_contents("http://localhost:8000/project-29-06-2022-06-22");
$html = ob_get_contents($content);
ob_end_clean();
$mpdf->WriteHTML($html);
$mpdf->Output( $postsDirectory .'/'. $projectName .'.pdf', \Mpdf\Output\Destination::FILE);
}