简体   繁体   中英

phpdocx - how to make image being flooded by text?

I started to use PHPDocx library. I am still not sure if it is the best way to make docx files from PHP. For now I am stuck with such a problem:

I have an image and a long text. I'd like to have this image to be flooded (not sure if i use correct word to describe - sorry for that) by text. It should look like this:

text text text text text text  ---------------------------
text text text text text text |                           |
text text text text text text |         I M A G E         |
text text text text text text |                           |
text text text text text text |___________________________|
text text text text text text text text text text text text 
text text text text text text text text text text text text 

My code looks like this:

$paramsImg = array(
'name' => '/images/image.jpg',
'scaling' => 1,
'spacingLeft' => 100,
'spacingTop' => 100,
'spacingRight' => 100,
'spacingBottom' => 100,
'textWrap' => 3,
'border' => 3,
'jc' => 'right'
);

$docx->addImage($paramsImg);

$paramsText = array(
    'jc' => 'both',
    'font' => 'Calibri'
);

$str = 'text text text text text';

$docx->addText($str, $paramsText);

Although I use multiple 'wordwrap' parameters and so on it always looks like this:

 ----------------------------
|                            |
|                            |
|          I M A G E         |
|                            |
|____________________________|
text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text 

It also doesnt matter what is displayed first - text or image. Do you have any experience in image processing with phpdocx? Or maybe you can advice any other library to make dynamic doc files?

EDIT: one more thing - all formatting to image doesnt work - there is no border although it should be, spacing also doesnt work.. Dont know why.

EDIT 2: Because all the libraries I found didnt suits my needs I decided to make my docx file as word 2003 xml file. With it you can do with text all you want! Hope it helps!

Since version 2.6 of PHPDocX PRO there is a addParagraph method that allows you to insert complex paragraphs that may include:

  1. formatted text
  2. floated images (with the format you are looking for)
  3. bookmarks
  4. footnotes
  5. endnotes

You may also use the embedHTML method for similar results (if you are working with templates the option is replaceTemplateVariableByHTML())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM