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.
Related
I have a problem with a HTML table generated with a PHP class and saved into a variable.
This variable also contains text, saved before the table, but the table is displayed before the text.
Here's what I do :
Put a text in a variable :
$RET='Awesome introduction';
Generate a table with a class of my own (it's still a simple table) :
$TAB=new class_table();
$TAB::add_th('Column'); // saves 'Column' in a 'th' 3D array
$TAB::close_line(); // $num_tr++
$TAB::add_td('Cell'); // saves 'Cell' in a 'td' 3D array
$TAB::display(); // generate the table
When I do this :
$RET='Awesome introduction';
$RET.=$TAB::display();
echo $RET;
... I've got the table before the text.
When I do this :
echo 'Awesome introduction';
$TAB::display();
... I've got the table after the text, and that's correct.
When I generate my table without the class, it's correct too, of course.
Do you know if it's normal (maybe the class' call is executed in first ?) and if I can workaround this ?
I ask because this code is a just a easy sample, the real one is much complex and called with AJAX (and a console.log proves that the table is generated before the text). I hope I'm clear enough.
Thank you.
Yes, probably Completely normal. This Display class is probably doing exactly that. Displaying, not returning values. You are assigning nothing to the $RET.= , You can prove it by echoing it a second time, it will print your header a second time but not your table. At the time that you assign nothing to RET you output the table, probably with print statements or echo statements in the Display class. There maybe be some way to use the eval function to capture the output of the Display class, but that's above my pay grade. (This would just be a comment, but i haven't earned the privilege.)
I'm trying to create a PDF file with a form. I'm using php and tcpdf.
The text fields need to be precisely positioned to fit the image in the background.
Some of the text fields have default values (via the 'v' attribute).
The issue is that when I click the text field to edit the contents, the text moves a few pixels to the side (probably because of the border around the active input field). When the input loses focus, the text does not return to the original position.
I've tried to visualize the problem with these screenshots:
(note the text position relative to the line below)
My form default settings:
$pdf->setFormDefaultProp(array('lineWidth'=>1, 'borderStyle'=>'solid',
'fillColor'=>array(), 'strokeColor'=>array(255, 128, 128)));
This is the code for the field:
$pdf->TextField('test', 47, 6, [], ['v' => 'test(12)'], 8, 13);
What I have tried so far:
setting the lineWidth to 0, but while the border is no longer visible, the text still moves.
setting the borderStyle to 'none', same result.
setting the strokeColor to [], same result.
What I would like to do:
set a padding to the default value (or otherwise influence its positioning)
or
remove the border from the active form field (not just make it invisible)
I noticed the same behavior on the TCPDF example here: https://tcpdf.org/examples/example_014/
If you click into the address field, the text moves up and to the left.
While I couldn't solve the problem with PHP, I managed to find a viable workaround (at least for our project):
If I insert the default values via Javascript, the effect doesn't occur.
$js = "
var fields = {'field1':'test', 'field2':'test2'};
for (var fieldName in fields) {
if (!fields.hasOwnProperty(fieldName)) continue;
var field = getField(fieldName);
if (field && field.value === '') {
field.value = fields[fieldName];
}
}
";
$this->pdf->IncludeJS($js);
This has the drawback, that if the user empties a field, the default value will be filled in again on next opening the file. This is no use case for our project, so it works for us, but keep it in mind!
So it's by no means perfect, but it helped us move on with our project. And maybe someone searching for this problem finds this helpful :)
If anyone finds an actual solution, I'd still be grateful!
I think you want to distinguish the first time a user opens the (blank) form, from when they re-open it after they saved it with the field emptied.
In the textfield, set the value (or default value) to 10 blanks. In your javascript, first check for 10 blanks, and if there, insert your default values. If the field has anything but 10 blanks, don't insert defaults. The user is unlikely to use exactly 10 blanks to clear a field.
But if that isn't robust enough, use another textfield that the user would never edit (like a version number). Start with it empty, and insert the version number (or whatever) only after you have checked the field, and inserted your set of defaults.
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);
I'm making some pdf document from php code using fpdf library. In that document i have created two cell like this
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
above code works well, out put have two cells, first one has size of 100x100 and second has 35x35 , and second cell was just right to the first cell.
but i need to print that second sell inside the first cell
is there any way in fpdf ?
can anyone help me?
I'm not sure what you want exactly achive, but maybe this AddOn could help you to do this:
http://www.interpid.eu/fpdf-table
Other way would be moving the pointer, something like this:
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->SetX($pdf->GetX() - 35);
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
In Nested cell X-axis and Y-axis, I have achieved like this
`$pdf->Cell(190,20,"",1,0,'L');
$pdf->SetX($pdf->GetX() - 189);
$pdf->Cell(100,10,'First ',2,0,'L');
$pdf->Cell(90,10,'March/2020 ',2,0,'R');
$pdf->SetY($pdf->GetY() +5);
$pdf->Cell(100,10,'MCB,UBl Omni, HBL Konnect, Alfalah , Mobi Cash ',2,0,'L');
$pdf->SetY($pdf->GetY() +5);`enter code here`
$pdf->Cell(139,10,'third text he`enter code here`re ',2,0,'L');
$pdf->Cell(50,10,'Lahore',2,0,'R');`
I have a weird question. I want to create script in javascript (or PHP if I have to, I'm just more comfortable in javascript) that reads through a table until it finds specific text (know how to do that) and then returns the text three cells to the right.
To be specific, I want a script that finds a row for a specific printer on this site and returns the printer's status. I know how to select unique text, but not so much about nonunique text.
Try this
$('.epi-dataTable tr:gt(0) td:first-child:contains("printerName")')
.closest('tr').find('td:eq(4)').text();
var printerName = 'yourname',
status = $(':contains(' + printerName + ')').siblings().eq(2).text();
If I understood your question correctly, this is how you could do it using jQuery:
$("td").filter(function() {
return $(this).text() === yourSeachText;
}).next().next().next().text();
Clarifying: the filter function will select only the column whose text equals your search text, and each call to next will return the column's next sibling - another td. Three calls later, you have the column you want, so you can get its text.
Update: you might also be interested in this question, if the site you're querying is not in the same domain as your script. If it is, you can simply load its contents to a div before querying it:
$("#placeholder").load("http://clusters.andrew.cmu.edu/printerstats/", function() {
// The contents were loaded to #placeholder, do your query here
});
If it's not, then you'll have to load that html data somehow, and according to an anwser to that question, your best route is really to do it in PHP (or at least use it to echo the other site's contents to your own).