Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert image in TemplateProcessor #1079

Closed
gmmaraccini opened this issue Jun 21, 2017 · 4 comments · Fixed by #1170
Closed

Insert image in TemplateProcessor #1079

gmmaraccini opened this issue Jun 21, 2017 · 4 comments · Fixed by #1170

Comments

@gmmaraccini
Copy link

gmmaraccini commented Jun 21, 2017

When I create a file through TemplateProcessor, it does not add images.

I would like a simple example of how to do this. The idea is to put a logo on the document that repeats on every page


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@troosan
Copy link
Contributor

troosan commented Jun 26, 2017

I do not think you will be able to achieve this with the TemplateProcessor as as far as I know it does not allow you to add images to the archive.
You could try to unzip the docx, add the image to the correct directory (word/media) and then replace a placeholder with the "correct" XML like in issue #1082 but it's not going to be easy!

@troosan
Copy link
Contributor

troosan commented Jun 27, 2017

you can try out the pull request #1084 which seems to be doing exactly what you want

@FBnil
Copy link

FBnil commented Sep 26, 2017

You can add a dummy image with the right size and location (for example, in the footer), then open your docx with zip, and see where your dummy file is located (relative path and name)

$fileindocx = "word/media/image2.jpeg";
$newimage = file_get_contents($fqnameofjpeg);
$templateProcessor = new TemplateProcessor($file_dir);
$templateProcessor->zipClass->AddFromString($fileindocx ,$newimage );

For these actions, you need to save to disk. $templateProcessor->saveAs(...)
The new image will have the position and dimensions you gave the dummy image. (at least, libreoffice shows no errors on opening the file)

@rkorebrits
Copy link

@FBnil, zipClass->AddFromString works perfect, however zipClass is a protected method... I've made it public for now, but gonna cause issues with composer. What do you suggest? Should we make it public?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants