Forum


Replies: 6   Views: 4180
Addtext doesnt make text bold and 20 points fontsize
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 jasonva  · 13-06-2014 - 13:00

I tried to modify the text i add to my docx but the options doesnt work my code: $salutationText = array(); $salutationText[] = array( 'text' => $salutation . ' ' . $survey->getFirstname() . ' ' . $survey->getLastname(), 'bold' => 'true', 'fontSize' => '20' ); $this->addText($salutationText, array('bold' => 'true', 'fontSize' => '20')); i'm using the trial version, isn't it working because i used the trial version?

Posted by jorge  · 16-06-2014 - 14:39

Hello, Please check and run the included examples, to get it everything is working fine. For example these code: -------------------------------------------------- //path to the CreateDocx class within your PHPDocX installation require_once '../../../classes/CreateDocx.inc'; $docx = new CreateDocx(); //A paragraph composed of two runs of text with different properties $text = array(); $text[] = array( 'text' => 'We know this looks ugly', 'underline' => 'single' ); $text[] = array( 'text' => ' but we only want to illustrate some of the functionality of the addText method.', 'bold' => true ); //we also add some borders to the paragraph to illustrate that functionality $paragraphOptions = array( 'border' => 'double', 'borderColor' => 'b70000', 'borderWidth' => 12, 'borderSpacing' => 8, 'borderTopColor' => '000000'//we overwritte the top border color property ); $docx->addText($text, $paragraphOptions); $docx->createDocx('example_addText_2'); -------------------------------------------------- generates a DOCX with some styles. Regards.

Posted by jasonva  · 17-06-2014 - 11:44

i had already tried this example code but it doesnt work. i dont get a bold text or a underline text

Posted by admin  · 17-06-2014 - 13:43

Hello, We're running the example with two servers and it generates the document perfectly. How are you opening the DOCX? Please post your OS, PHP version and the program you use the open the document. Regards.

Posted by jasonva  · 24-06-2014 - 06:27

require_once 'phpdocx_3.6/classes/CreateDocx.inc'; define('PHPDOCX_INCLUDE_PATH', '/opt/web/php/includes/phpdocx_3.6'); spl_autoload_unregister('my_autoload'); require_once PHPDOCX_INCLUDE_PATH . '/classes/AutoLoader.inc'; spl_autoload_register(array('AutoLoader', 'load')); spl_autoload_register('my_autoload'); class PHPDocx extends \CreateDocx { /** * @var string */ protected $language; /** * constructor */ public function __construct($language) { parent::__construct(); $this->setLanguage($language); } /** * createAndDownloadDocx * @param SurveyModel $survey * @param array $answers */ public function createAndDownloadDocx(SurveyModel $survey, $answers) { $this->setDefaultFont('Arial'); $salutation = ($this->getLanguage() == 'nl') ? $survey->getGender()->getNameNlBE() : $survey->getGender()->getNameFrBE(); $salutationText = array(); $salutationText[] = array( 'text' => $salutation . ' ' . $survey->getFirstname() . ' ' . $survey->getLastname(), 'bold' => 'true', 'fontSize' => '20' ); $this->addText($salutationText, array('bold' => 'true', 'fontSize' => '20')); $this->embedHTML('

' . $GLOBALS['lang']->getLang('str_birthdate') . ' ' . htmlspecialchars($survey->getBirthdate()) . '

'); $this->embedHTML('

' . $GLOBALS['lang']->getLang('str_filled_in_date') . ' ' . htmlspecialchars($survey->getCreation()) . '

'); $this->embedHTML('

' . $GLOBALS['lang']->getLang('str_answers') . '

'); foreach ($answers as $answer) { $this->embedHTML('

' . ($this->getLanguage() == 'nl') ? htmlspecialchars($answer[0]->getQuestion()->getCodeNlBE()) : htmlspecialchars($answer[0]->getQuestion()->getCodeFrBE()) . '

'); foreach ($answer as $ans) { $color = ($ans->getAttention() == 'Y') ? 'FF0000' : '000000'; $name = ($this->getLanguage() == 'nl') ? $ans->getNameNlBE() : $ans->getNameFrBE(); $listArray[$ans->getQuestion()->getId()][] = $this->addText(htmlspecialchars($name), array( 'color' => $color ) ); } $this->addList($listArray[$answer[0]->getQuestion()->getId()]); } //$this->embedHTML('

' . htmlspecialchars($GLOBALS['lang']->getLang('str_details_message')) . '

'); $this->createDocxAndDownload('/tmp/report_' . htmlspecialchars($survey->getFirstname()) . ' ' . htmlspecialchars($survey->getLastname())); unlink('/tmp/report_' . htmlspecialchars($survey->getFirstname()) . ' ' . htmlspecialchars($survey->getLastname()) . '.docx'); } This is how i make the docx export

Posted by admin  · 24-06-2014 - 07:05

Hello, I see you're using phpdocx 3.6. The posted example is for phpdocx 4.0. We recommend you to download phpdocx 3.7 on MYPHPDOCX page after login and check the old documentation on: http://old.phpdocx.com/documentation/api-documentation Although we strongly recommend to upgrade to phpdocx 4.0. Regards.

Posted by jasonva  · 24-06-2014 - 08:44

thanks it works fine now ;) updated my docx version