-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add/Insert/Replace image in templates #550
Comments
I've come up with a hack solution see |
class PHPWord_Template {
} use example: $PHPWord = new PHPWord(); ); |
This is a full example: |
I have an issue. When i get file content from Google Drive API and create the file. This function doesn't seem to be able to replace the image. Would be grateful if you could help out |
Hi emirpolo. Do you have an example with the new version 0.12.1? |
I was looking for a solution to add image. I read a lot of articles, I only found suitable solutions for older versions. Changing and finalized the decision to get the code.
} public function save()
} //add function
//add function
//HOW TO USE???
//variant 2
//Save
|
Great! |
Bien Muchisimas Gracias |
thinks labsev |
Hi, I get this error: Undefined property: PhpOffice\PhpWord\TemplateProcessor::$_rels
|
@karupi You should add them as properties. I had the same error and fixed it like this: class TemplateProcessor
{
const MAXIMUM_REPLACEMENTS_DEFAULT = -1;
// add these two properties
protected $_rels;
protected $_types;
[...]
} |
@labsev Thanks! It work! great job! 👍 |
@labsev Thanks a lot! It works. |
Exactly on which version is working this solution? |
It's definitely working on v0.13.0 @labsev, what's exactly $_countRels is used for? |
nice work, thanks labsev, its works for me :) |
@labsev Yeah, finally it works for me now. Thx a lot! |
I know this is over a year old, but @labsev thanks so much! |
Thanks @labsev . |
Hi all, thanks for all the work! I'm trying to use @labsev 's code, but I'm a little confused as to what placeholder text I should put in the template, something like ${IMAGE}? Would be great if someone could show me an example! |
If you are using ${IMAGE_index} in the template, you have to pass to setImg only this : 'IMAGE_index' |
Oh, I see, thanks!! |
@labsev Thank you very much. Great solution for inserting images! |
Works great, thanks. If you're inserting multiple images and get 'corrupted' warning message while opening the doc. Increase the $this->_countRels=100 to $this->_countRels=300 for instance. Changing the number cured it for me. |
Thanks!!!!!!!!! |
我的神 |
The @labsev solution is not working when I try to replace the image inside the header |
No, it does't you need to create the implementation for that |
how can you add the image in the document header? please |
Sounds like a bug that needs to be fixed before being a candidate to be merged into PHPWord... |
@labsev Hello sir, I have some issue, I follow the lead but still get error, Sorry my English bad |
thanks @labserv, its really work |
thanks @labsev very good |
This solutions looks great. How would you recommend including into our laravel project when the project hasn’t merge this? Currently we using composer and ideally didn’t want to have to store as a local dependancy. |
@andy-hammond what you can do is extend the class with the particular function. That could be a good practice until they choose merge it. |
@levieraf thanks for the tip. I hope they merge this soon! So essential. |
@labsev I am using this and it works great, however I would like to be able to pass in content rather than a locally saved file. Can anyone provide any suggestions? Thanks |
Labsev's solution still works using v0.14.0. |
do this with laravel it work! thanks so much! |
I've forked and extended template processor to allow you to insert an image placeholder (any image) in MS Word, size it how you want, then set the alt text to bind it to your data as you would with setValues. The distinct downside to using setimagevalue is that you can't really see how the size of the image will affect your document until you generate. |
Hi,
Can't we still Add/Insert/Replace an image using template files? Need this urgently... Does anyone has a solution?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: