I managed to get this working.... somehow
if ($attchments = $userDoc->attachments) {
/** @var \App\Models\UserDocAttchment $attachment */
foreach ($attchments as $attachment) {
$filePath = Storage::disk($attachment->disk)->path($attachment->path.'/'.$attachment->filename);
$docx->addSection('nextPage');
$attachment_image = new WordFragment($docx, 'document');
$attachment_image->addImage([
'src' => $filePath,
]);
$docx->insertWordFragment($attachment_image);
}
}
now 2 problems: It's not on a new page at the end but in the middle of the text and the document is now 50 pages long
The image that I try to insert is 480x640 pixels (72 DPI)