This project is read-only.

Placing an image beyond the page margins

Jul 1, 2011 at 5:05 PM

Hi,

Is it possible to place an image beyond the page margins? I have a banner image for my 1st page that I would like to extend all the way to my page border. However, my page margins prevent image from being placed beyond the left margin. I could reduce my margins, however then all of my text is right against my page border, and it looks funny. I tried using a separate section for the image, however it appears that I can not have multiple sections per page- the new section just creates a new page in the word doc. 

Is this possible to do? How should I do it?

Thanks

Jul 21, 2011 at 10:59 PM
Edited Jul 21, 2011 at 11:11 PM

An update:

I have not gotten it working, but I think I made progress. I placed my header content into a table, and then set cellMarginLeft to -1440. This did not work, but I dug a little deeper. When I looked at the margins for the table (in word 2010), the Left margin was indeed set at -1". However, when I tried to change it to another negative value, Word gave me an error. So it looks like that while a negative value is set, it won't actually go there.

I dug a little more, and noticed that my table indent was set at .5", exactly half of the absolute value of cellMarginLeft. Playing around with this number (in Word), I can get the table to move into the margin space by setting a negative value. So it looks like if I can somehow set the table left indent to a negative number, I can place the table in the margins, and then my header image will extend into the margins. 

Does anyone know how I would go about doing this? I've started to look into the PHPWord source and see how it sets options. I've also started looking at the openXML specs, but I haven't turned up anything yet.

Edit:

https://openxmldeveloper.org/discussions/formats/f/13/p/838/2093.aspx#2093

It looks like this might be how to do it. Now to somehow get php to do it....

Jul 22, 2011 at 8:27 AM
Edited Jul 22, 2011 at 8:29 AM

Yet another update!

I figured out how to do it! I had to modify 2 or 3 core PHPWord files, but what I basically did was add a new table style property, 'tableIndent' to the code. This sets the "w:tblInd" field in the XML files. When this is set to a value (in twips) the table is indented from the margins. This works for positive AND negative values, so I can now indent my table (with images) into the margins!

I am working on a writeup on how to do this, and double checking my code for any errors. I will post it here in the next couple of days.

Hopefully people find this helpful!

Dec 4, 2011 at 7:28 PM

Hi Agaz623

Same problem here. Would be thankful for the code modifications.
Otherwise I have to figure it out again.  

Thx!

Dec 7, 2011 at 4:52 AM

Sure thing. It has been a while since I made the modifications, but I'm going to try to track down the modifications and I'll post what I changed.

Dec 7, 2011 at 5:13 AM

Ok, I think I have all of the files I modified. I have attached them in a .zip file. Here is what is modified and where it should go.

PHPWord/writer/Word2007/base.php
PHPWord/writer/Word2007/styles.php
PHPWord/Style/Table.php
PHPWord/Style/TableFull.php

The "tableIndent" property of the table style is what I added. Setting that to a negative value should shift it into the margins. The value is in TWIPs Here is an example of it in use:

$header = $body->createHeader();
		$hTable = $header->addTable(array('cellMarginRight' => 300, 'tableIndent'=>-1000));
		$hTable->addRow();
		$hCellL = $hTable->addCell(2500);
		$hCellL->addImage('images/standard/logo_footer.jpg', 'alignRns');
		$hCellR = $hTable->addCell(5000, array('valign' => 'center'));
		$propText = $hCellR->createTextRun('alignR');
		$propText->addText('System Proposal ', $bold);
		$propText->addText($proposalNum);

 I think I have included all of the files I modified. If this doesn't work, let me know, and I can try to track down how the files interact with each other and figure out what I missed. There should be comments where I inserted changes.

Download the files here: http://agprojects.net/phpword_indent_mod.zip

Dec 9, 2011 at 10:26 PM

Thank you agaz623. No time to try it right now, and I will ;)

Jan 20, 2012 at 10:58 AM

Right click the picture. Then from drop down menu select Text Wrapping > Through. Now you'll be able to move the image beyond margins.