I'd started to use PHPWord to generate DOCX/ODT from my PHP application.
While it mostly works "out of the box" for me, there is an issue, while trying to add "Horizontal line" to my generated document.
This code just adds nothing, and I can't figure out what's the problem:
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addLine(array('dash' => 'dash', 'width' => 100, 'height' => 2, 'weight' => 10));
$phpWord->save(wp_upload_dir()['basedir'].'/test.odt', 'ODText'); // it won't display horizontal line in DOCX either
Thanks for help
Related
I´m having a problem with phpword (https://phpword.readthedocs.io/en/latest/index.html)
I want to create a line where all the background is one color (100% width), but I can only make the background the size of the text.
$titleStyle=array('name' => 'Calibri','size' => 11, 'align' =>'center','marginTop' => 10,'bgColor' => 'd0cece');
// Create a new table style
$table_style = new \PhpOffice\PhpWord\Style\Table;
$table_style->setUnit(\PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT);
$table_style->setWidth(100 * 50);
$table_style->setBgColor('d0cece');
// Set up our table.
$tableTitle = $section->addTable($table_style);
$tableTitle->addRow();
$tableTitle->addCell()->addText('Identificação pessoal',$titleStyle);
Someone can help me?
I'm not really familiar with PhpWord, but have you tried to set width of a cell to 100% of document?
$titleStyle = array(
'name' => 'Calibri',
'size' => 11,
'align' =>'center',
'marginTop' => 10,
'bgColor' => 'd0cece',
'width' => 11905.51181102
);
From what I see in the docs, cell width needs to be provided in twip units, which after conversion from 210mm is 11905.51181102 (A4 page width)
https://www.translatorscafe.com/unit-converter/en/typography/1-3/twip-centimeter/
I have this problem. I Don't know how to explain.
When I add thai font (TH sarabun) into .ttfonts folder.
and config in config_fonts.php file
follow this:
"sarabun" => array(/* Thai */
'R' => "THSarabun.ttf",
'B' => "THSarabun_Bold.ttf",
'I' => "THSarabun_Italic.ttf",
'BI' => "THSarabun_Bold_Italic.ttf",
'useOTL' => 0xFF,
),
//similar garuda font'
//"garuda" => array(/* Thai */
// 'R' => "Garuda.ttf",
// 'B' => "Garuda-Bold.ttf",
// 'I' => "Garuda-Oblique.ttf",
// 'BI' => "Garuda-BoldOblique.ttf",
// 'useOTL' => 0xFF,
// ),
Then I coding mpdf follow this (I assume my code isn't error.)
$this->pdf = new mPDF();
$html = $this->load->view('.........');
$this->pdf->writeHTML($html);
$this->pdf->Output();
Then mPDF displays the square text and text.
follow this:
The square text is wrong or bad reading
I want to remove square text or don't want to show or disappear.
How should I solve these problems?
P.S.
If I remove 'useOTL' => 0xFF is correct display.But Word wrapping is bad.
It's more than space when I used justify text. or some line is short. Some line is long.
example:
We have a website that is currently on an Ubuntu 16.04 server and we are working on moving to Amazon. The rest of the site (Written in PHP Yii 1.1) is working fine except for the piece that present our reports in PDF format.
The report is written to pdf with no real issue but images show as a red X After some debugging I came to the conclusion that the majority of the images are png images and that is why they do not show. The single jpg image on the report is showing.
How can I get this to work? The html version of the report (that uses different code) gets the image from the same place and that works just fine. I cannot really convert all images because they are generated dynamically.
I read somewhere that pdf does not support png images, REALLY?? Why did it render just fine on the current server?
I do not believe that is is going to help but here is some code used:
main.config:
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)
),
),
Controller:
$mPDF1 = Yii::app()->ePdf->mpdf('utf-8', 'A4');
$mPDF1->simpleTables = true;
$mPDF1->useSubstitutions = false;
$mPDF1->WriteHTML($this->renderPartial('pdfRXMapFile', array('model' => $model)));
I'm trying to create a TextBox without a border in PHPWord, but setting borderColor or borderSize to 0 or null has no effect and I always get at least a black border around the text box.
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$textbox = $section->addTextBox(
array(
'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END,
'width' => 200,
'height' => 40,
'borderColor' => null,
'borderSize' => 0,
)
);
$textbox->addText('dummy-text ...', null, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::END));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord);
$objWriter->save('dummy.docx');
To create a borderbox without border you can use (git issue: no outline textbox):
'borderSize' => 'none'
Tested and working with PhpWord 0.13.0 & opening the generated document with MsWord (libreoffice didn't seem to recognize this setting)
If anyone is still looking for an answer in PHPWord 0.17 following solution works:
'borderColor' => 'none'
I´m using PHPWord to generate the file .docx from html tags.
But img tag in HTML Reader (PHPWord) is unavailable.
Html reader supports these tags:
`<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,
<strong>,<em>,<sup>,<sub>,
<table>,<tr>,<td>,<ul>,<ol>,<li>.`
I specifically want to know if anyone could tell me how to read the img tag with phpword to see images in my .docx
I need to modify this file to read img tag.
Thank you very much.
You can use following:
$section = $phpWord->addSection();
$section->addImage(
'mars.jpg',
array(
'width' => 100,
'height' => 100,
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
See Documentation of PHPWORD