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 front of text #1087

Open
valisirius opened this issue Jun 30, 2017 · 6 comments
Open

Insert image in front of text #1087

valisirius opened this issue Jun 30, 2017 · 6 comments

Comments

@valisirius
Copy link

valisirius commented Jun 30, 2017

Hello,

Please tell me if it is possible to insert an image in front of text and on every page, in the same position, when creating a new docx file.
This feature can be useful.

Thank you.


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

@troosan
Copy link
Contributor

troosan commented Jun 30, 2017

If you want to repeat the image on every page, the only way right now is to put it in the header.

@valisirius
Copy link
Author

valisirius commented Jun 30, 2017

Indeed, but the image in the header is behind the text. Can we create an artifice to put the image in the header in front of the text?
On the other hand I saw that we can put image in every section. But only if we create explicitely a section. Maybe if we could detect a 'page break' process, we could then create a new section and insert a new image (with 'wrappingStyle' => 'infront'). Could we do this?

@troosan
Copy link
Contributor

troosan commented Jul 1, 2017

We cannot detect when a page break is happening, except if you explicitly put one of course.
And in that case you can of course put the image again. To wrap the text around please check http:https://phpword.readthedocs.io/en/latest/recipes.html

@valisirius
Copy link
Author

valisirius commented Jul 4, 2017

Thank you, troosan. I can add that the scenario is: I have a document, with a single section, containing a table which can ocupy a page or more pages and I want to put a stamp/image on every page, in the same place, in front of the text from table.
Header allows to put an image on every page, behind the text from table - not OK for me.
Footer allows to put an image on every page, behind the text from table, but in front of the text from footer.
Also I tried to build the final docx from two steps: one step builds a document with a fake header and the second one loads the document and attach the correct stamp in the header, but without good results for me.

@FBnil
Copy link

FBnil commented Oct 3, 2017

@valisirius
Ok, I got something that is working, but it is based on my branch. I recently added ${myblock/}, this actually is a single element block that searches for the paragraph edges where it is found (useful for bulletpoints).
The trick is naming the image ${myimage/}, anchor the image to the page and with getBlock() you can get the block, then paste it inside a block on the second page with

	$block = $templateProcessor->getBlock("myimage/");
	$templateProcessor->replaceBlock("page2", $block);

This resulted for me in 2 pages with the same image at the same relative page position. The receiving block must have something in it, for example, a newline:

${page2}
${/page2}

nb: Not necessarily the image name, you can also drop a singleton blockname somewhere inside the description or alternative name, and use that blockname. As long as you see:

<pic:cNvPr descr="${mydescription/}" name="${myimage/}" id="1"/>

To test it:

Just (temporarily) replace this file:
https://github.com/FBnil/PHPWord/blob/develop/src/PhpWord/TemplateProcessor.php

you can also capture a pagebreak with getBlock() and insert it back as a "new page" creating element

@49167386
Copy link

Insert a shape to the template word. Set the shape text like ${image}. The shape can set in front of text. Use setImageValue can insert image in front of text.
https://phpword.readthedocs.io/en/latest/templates-processing.html#setimagevalue

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

No branches or pull requests

4 participants