PHPWord TemplateProcessor PageBreak - php

I have a word template that is a single page, its something like this:
${blockToClone}
two tables
${pageBreak}
${/blockToClone}
I generate X numer of copies as needed with:
$template = new TemplateProcessor('path to template');
$template->cloneBlock('blockToclone', number of copies, true, true);
And for each block cloned, I replace the pageBreak like this:
//For example I generate 5 pages, so index goes from 1 to 5
$template->setValue('pageBreak'.$index, '<w:r><w:br w:type="page"/></w:r>');
//And for the last index(last page) I set as value for pageBreak an empty string
The problem is that, when I set values for the tables, if the second table of each block ends near the end of the page, it inserts a blank page:
Page 1, second table ends near end of the page(last line of the page or the previous one)
Blank page
Page 2
Page 3
Page 4, second table ends near end of the page(last line of the page or the previous one)
Blank page
Page 5
Is there someway to avoid the blank pages?

Related

Html tag in the string not working in browser

I am trying to display some information coming from the database. Database field takes the input from the ck-editor and save the HTML as a string.
Now when I am trying to display those data it comes like as the blue section in the above image. But I want it as the red section.
echo "Product Name : Personal Loan<span><br>Loan Range :<br>Minimum : 50000<br>Maximum : 2000000<br>Loan Repayment Tenure :<br>Minimum 1 Year<br>Maximum 5 Years</span><br>";
When I use this code the red block section of the above image is showing
but when I use
echo $infos['Loan']['addtional_features'];
the blue section is showing. that is, the all string with the tag is displaying.
What could be the reason?
It seems like the string stored is HTML-encoded twice (e.g. <br>, instead of <br>). Try to html_entity_decode() your string, before to write it in the output.

Change image using innerHTML and show back and previous button according to result

I have images of alphabets. I want to to change the image from A to B when press next button usin innerHTML. When it is "A", only next button should display.When it is "Z", only previous button should displayed. else both button button should display..Which code will work in php??
In your case JS looks a bit better but with PHP a short hint for you. Build an array and look which image is shown in the array (the position). Then you can check if you are at the end of the array in that case the index is the length of the array.
Then you can work with if else. So i don't give you the exact code Stackoverflow is to learn and find solutions for existing problems.
$alphabet = array(
0 => 'pathtoA',
1 => 'PathtoB'
....
);
So when you now print A for example you know that its the key 0 and that 0 is the first position so you can show only the next button with an if.
count($alphabet);
With count you get the length and you can look if your current id is the last element and you show only the preview button.
This is a very simple solution but i think if you read a but you get a solution on your own.

How to put a content between two text in a file into an array or a string

For example, this is top-most part of "how-to.html"
1 <!-- Table of Content -->
2 <ol>
3 <li>Intro</li>
4 <li>Conclusion</li>
5 </ol>
6 <!-- / Table of Content -->
7
8 <article>
9 <h2>Introduction</h2>
10
The content between "!-- Table of Content --" is not fixed and may extend or shrink.
How to only put the contents between the HTML comments into an array or a string?
I tried to search on the method however I was unable to find anything like this. The things I found are about changing contents between lines. Since "how-to.html" will grow overtime, I need to only read the content from specified texts, not lines.
You can provide a modified example of the "how-to.html" to reflect your answer.
You can load the file into an array using file().
$file = file('filename.html');
Then you can use array_splice() to insert into a portion of it.
$newlines = array(
'<ol>',
'</ol>'
);
$file = array_splice($file, $line_num_to_insert_at, 0, $newlines);
You will still need a way to find the line numbers, I'll leave that up to you to do some research.
array_splice can insert into an array at a certain position and also replace existing content in the array. Look at the manual for more info on how to use it. The function I provided only inserts, it doesn't replace.

TCPDF writeHTML()

I am working on two column layout input comes from an editor which has images and text. Images can come as one column or full width. Everything works fine when I insert images in one column. But when I insert image as 2 column it fits perfectly in the column but the text after that is somewhat not aligned.
Text covers the after space correctly but when it goes to second column some space from the top till where the image ends on the first column is blank and starts after that.
if ($this->myResetColumn) {
$this->resetColumns();
$this->setEqualColumns($this->myCols, $this->myWidth);
$this->setXY($this->GetX(), $this->GetY());
$this->selectColumn();
}
$this->writeHTML($content, true, false, true, false, $align);
Second Question
It there a way, I can make few checks while the writeHTML() function is executing or I have to change the function itself, which will not be a good idea to change the source code.
For AddPage, I override it, after the line at the end like this
$this->startPage($orientation, $format, $tocpage);
if (condition) {
// some function call
}
but writeHTML() is a lengthy function to override and it will lose many options it has.

TCPDF: Two Independent Columns with page break

I want to create a page with 2 independent columns. If the text does not fit in one colum on one page it should be continued on the next page with the same column setup.
I tried using setColumnsArray and selectColumn the problem with this is, that if the first column is full it continues on the next column instead on the next page.
It there a posibility to achive this?
Thank You
See Sample10 which is doing exactly what you are asking for:
PHP Source code: http://www.tcpdf.org/examples/example_010.phps
Final PDF: http://www.tcpdf.org/examples/example_010.pdf
Sample7 might help too but column spreads over multiple pages:
PHP Source code: http://www.tcpdf.org/examples/example_007.phps
Final PDF: http://www.tcpdf.org/examples/example_007.pdf
I solved the problem now without writing everything in html.
I used to following aproache:
Save the top of the columns with getY and getPage.
Write the first column
Use setY and setPage to go back to the top of the second column
Use setX to move the seconds column on the right side.
Using the following hack to get around the problem with different page borders on right and left pages on the second column:
if ($curPage<>$pdf->getPage())
{
$curPage=$pdf->getPage();
if (($curPage % 2)==1)
{
$xPos+=15;
}
else
{
$xPos-=15;
}
}
$pdf->SetX($xPos);

Categories