Forum


Replies: 6   Views: 4028
Trying to keep on the same page with html: text and image with breaks between
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 wcalhoun  · 17-08-2015 - 18:19

I am trying to find a way to keep a block of content on the same page that goes like this: Text Image Text So I have text, then a new line, then an image, then a new line, then more text. Here is what I currently have: CSS: .figure{ text-align: center; page-break-after: avoid; } .figure span{ display: block; } HTML: <p class="figure"> <span>Text 1</span> <span><img src="path_to_image.jpg"></span> <span>Text 2</span> </p> This is working to keep the block on the same page, but the problem is, if 'Text 1' and the image can fit on the same line, it does that and doesn't cause a line break. I even tried manually putting <br> between Text 1 and the image and it still doesn't work.

Posted by admin  · 18-08-2015 - 07:27

Hello, Is Tidy enabled and running on your server? Regards.

Posted by wcalhoun  · 18-08-2015 - 14:05

I think so? This is what shows up in my php info: tidy Tidy support enabled libTidy Release 25 March 2009 Extension Version 2.0 ($Id: 14aff36094bdd63f1d0adee006215e5e553294ea $) Directive Local Value Master Value tidy.clean_output 0 0 tidy.default_config no value no value

Posted by admin  · 19-08-2015 - 08:41

Hello, The problem is how images are being added. When you add an image and text in the same paragraph, it set the text wrapping as in line with text. We recommend you to use a paragraph for each element you want in the same line and take out the image. Regards.

Posted by wcalhoun  · 20-08-2015 - 11:03

But I want the block to stay together, ie I don't want the first line of text on one page and the rest of it on the next page. I tried using the page-break-after: avoid in a div with p's inside but the only way it seems to work is by using page-break-after: avoid on a p. So how can I keep the block together but also keep everything on their own lines?

Posted by admin  · 20-08-2015 - 11:21

Hello, If the image and text go to the next page it's due to the image size that should be bigger than the page. Adding an image that fits in the same page doesn't create a new page. We recommend you to use a template with the needed placeholders and replace them with WordFragments or HTML to get the exact needed output. Using the MultiMerge class (http://www.phpdocx.com/api-documentation/docxutilities/merge-Word-documents-with-PHP) or the addExternalFile (http://www.phpdocx.com/api-documentation/templates/replace-variable-external-file-Word-document) you could merge the DOCX if needed. Regards.

Posted by wcalhoun  · 25-08-2015 - 11:19

The problem is I'm trying to build a completely dynamic document from custom HTML. So I wanted a way to say 'keep this block of text and images on the same page' when building the HTML.