Forum


Replies: 2   Views: 498
How to add new page and insert image
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by rabol  · 13-07-2023 - 09:50

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)