Full line background color - php

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/

Related

how to set height and width to image uploaded using setImageValue in phpword?

I am using this code and it is uploading the image to the docx it functions well,
but the problem the size of the image is too small I need to increase the height and width
$templateProcessor->setImageValue('image',[$image_path,['width' => 40,
'height' => 40]]);
it is not working
is it even possible?
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(asset('docx/job_application.docx'));
$templateProcessor->setImageValue('image',$image_path);
$templateProcessor->saveAs('docx/'.$file_name.'.docx');
In your template, set the bookmark to $[image:450:334}
$templateProcessor->setImageValue('image',['path'=>$image_path, 'width' => 40, 'height' => 40])
see https://phpword.readthedocs.io/en/latest/templates-processing.html#setimagevalue
$templateProcessor->setImageValue('image', [
'path' => $image_path,
'width' => 600,
'height' => 400,
]);

Yii 1.1 pdf extension not showing png images

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)));

Create TextBox without a border in PHPWord

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'

QRCode position does not follow the results of previous output in php using library TCPDF

I have a problem with position of qrcode in tcpdf.
First, I want a output of qrcode like this:
but after I added many rows inside of table, qrcode position doesn't follow with my table, like a picture below.
And this is my code
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', 0, 143, 50, 30, $style, 'N');
Please help me, what must I do with this problem.
With gladness, I say thank you for your help.

Create right floating image in PhpWord

I want an image on the right, text on the left floating around the image. The other way round works pretty good, there also is an example for that on the Recipies section in the documentation. However, I did not get this working with images floating on the right. What I tried:
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute'
)
);
or
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line'
)
);
I also experimented with negative image widths etc., but that did not work neither. Unfortunately, documentation on the whole project is really poor, at least at phpword.readthedocs.org.
I had the same problem too, and there's no answer on the internet to this date. So here's what I came up with:
$section->addImage('image.png', array(
'width' => 40,
'height' => 40,
'wrappingStyle' => 'square',
'positioning' => 'absolute',
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line',
));

Categories