Page margins on a PHP generated Word document (using fopen)
I recently posted a question on how to generate a .doc file without using the COM object - I had some great replies (thank you!) but unfortunately I need the document to be compatible with the old .doc format and not .docx since we're all using Office 2003 here, without the compatibility plugin.
I have the following code which generates a very basic document, but one that will probably do the job, the problem is the header image is very large (and essential) and won't fit in unless I lower the page margin... I tried chang开发者_开发百科ing the margin and padding of HTML/Body to 0 but had no luck unfortunately:
$fp = fopen("test.doc", 'w+');
$str = "<html><body><img src=\"http://url/header_image.png\">
<B>Content</B></body></html>";
fwrite($fp, $str);
fclose($fp);
You are not actually creating a Word file, just a HTML file that Word is formatting using its own internal renderer.
You may as well just distribute them as html
files.
The only benefit I can think of is that you only have to target versions of Word rather than all browsers.
A couple years late, but it might help someone else: http://sunsetsoftware.blogspot.com/2012/01/how-to-create-word-document-with-html.html
@page Section1{
size: 29.7cm 21cm;
margin: 2cm 2cm 2cm 2cm;
mso-page-orientation: landscape;
mso-footer:f1;
}
That is the interesting section. To make it portrait:
@page Section1{
size: 21cm 29.7cm;
margin: 2cm 2cm 2cm 2cm;
mso-page-orientation: portrait;
mso-footer:f1;
}
精彩评论