2

The following code generates a MS Word document in portrait format. But I need it to be in landscape mode as I’m inserting some tables, charts and similar multimedia stuff.

<?php 
$fp = fopen("tx1.doc", 'w+');
$str="here goes some of my content";
$str.="- -I insert tables, charts and all the stuff  with alignment--";
fwrite($fp, $str);
fclose($fp);
?>

So I wanna know how I can force php to generate the document in landscape format (landscape suits my presentation).

EDIT: as suggested by @Mark Baker I found solution to all of my requirements at one spot/shot github.com/PHPOffice/PHPWord Thanks. Now I can do anything with Doc ;)

krishna
  • 930
  • 1
  • 16
  • 35
  • 2
    How are you inserting those tables, charts and all the multimedia stuff? Doing that in Word format is usually pretty tough by hand... Are you already using some library? – deceze Jun 28 '12 at 12:35
  • Why am I thinking that you're simply writing HTML markup to your file – Mark Baker Jun 28 '12 at 12:41
  • @deceze tables am inserting by html, multimedia is not yet included. – krishna Jun 28 '12 at 12:56
  • @MarkBaker yes am generating some html tables and saving them in doc multimedia I've not yet included, am just trying that how much space I'll get if change portrait to landscape and am struck. – krishna Jun 28 '12 at 12:57
  • Then you're not producing an MS Word file. Just because you're calling .doc doesn't mean it is one. Use a library that can produce actual MS Word files in .doc or .docx format, which should also allow you to adjust the page properties. – deceze Jun 28 '12 at 12:58
  • @deceze well I've gone through this http://stackoverflow.com/a/4912602/1158603 it helped me but its not answering my problem, can you post any links if possible – krishna Jun 28 '12 at 13:31
  • More then enough libraries mentioned here: http://stackoverflow.com/questions/124959/create-word-document-using-php-in-linux – deceze Jun 28 '12 at 13:37
  • @deceze thanks. I've checked in all the links of the page, they say about good programming practices and different ways of getting things done, but my problem is not in just generating a ms word doc but its generating ms word doc with landscape format which is addressed no where – krishna Jun 28 '12 at 13:48
  • 1
    Your specific question isn't directly addressed.... but if you use some of the library tools listed that generate real .doc files (not simply html pretending to be word) then those libraries will almost certainly provide options for page layout including orientation... with html, you simply don't have that option – Mark Baker Jun 28 '12 at 15:32
  • 2
    Starter for 1.... PHPWord ( https://github.com/PHPOffice/PHPWord ) allows you to set page orientation in the settings, and can produce output as .docx, .odt or .rtf – Mark Baker Jun 28 '12 at 15:39

1 Answers1

1

You may try this to generate rtf document.

http://www.phpclasses.org/package/1805-PHP-Create-RTF-documents-from-HTML.html

jeevan kumar
  • 156
  • 1
  • 6