I am generating PDF using tcpdf,
I want to display whole content in 2 columns of same size,
Now the problem is , some content (like table) is getting overwrite on second column.
How to fit content in column width?
$this->resetColumns();
$this->setEqualColumns(2);
$this->selectColumn('');
$content = $_POST['pdf_content'];
$this->writeHTML($content, true, false, true, false, 'J');
the easiest way is to use only html, like this:
$content = '<html><table><tr><td>'.$_POST['pdf_content'].'</td></tr><table></html>';
$this->writeHTML($content, true, false, true, false, 'J');
Related
I write some lines in TCPDF with
$this->writeHTML('<p>blabla</p>', true, 0, true, true);
$this->writeHTML('<p>blabla</p>', true, 0, true, true);
What can I do to add some space between the two blocks? I tried
$this->writeHTML('<p style="margin-bottom:10px">blabla</p>', true, 0, true, true);
$this->writeHTML('<p>blabla</p>', true, 0, true, true);
but as I read later TCPDF can not translate margin-bottom. I could use Cells instead but I think then I would have to calculate their heights and so on to put them on the correct position, right?
Any suggestions?
In my PDF I need to create a cover page.
It would be very handy if it's possible to create the cover page, add further pages and while adding the other pages, go back to the cover page and add more content.
The following works well (Example1):
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
This generates a well rendered cover page.
The following doesn't work as expected (Example2):
// Add Cover page
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
// Add some content page(s)
$pdf->AddPage();
$pdf->writeHTML('<p>Content page...</p>', true, false, false, false, '');
// Go back to cover page and add more content...
$pdf->setPage(1);
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
The 2 lines on the cover page do overlap (or at least they are not positioned as well as in example1).
Is there any way to jump to an exising page and append some content?
Hm, got it.
You can get/set the Y-position of the current page.
The following works:
// Add Cover page
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
$start_y = $pdf->GetY();
// Add some content page(s)
$pdf->AddPage();
$pageNo = $pdf->getPage();
$pdf->writeHTML('<p>Content page...</p>', true, false, false, false, '');
// Go to cover page and add more content...
$pdf->setPage(1);
$pdf->setY($start_y);
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
// Go back to current page
$pdf->setPage($pageNo);
For some reason PHPStorm doesn't show this methods in the code completion, so I've overseen them...
I have the following tcdpf syntax in my php document:
$title="My Heading";
$obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.$title, PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
The logo appears on the left, how can I right align the logo and left align $title?
You must define custom header to align image.
This example
shows how to do this.
To align your logo right, you must set palign attribute to 'R' in image definition.
$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, 'R', false, false, 0, false, false, false);
Note that, your header data string position may not be what you want as. You will probably
need to play with several attributes, but in basic, image alignment can be done only via
overriding default Header() function as far as I know.
Check also Image() function.
I would like to add a 'imagebox' a box which contains the image and crops exceeding image value that is outside of this box. something like this:
I am not sure on how to do this if it's even possible.
Actually you can do this with Clipping.
The below line would show a photo of 200X300:
$pdf->Image('photo.JPG', 100, 100, 200, 300, '', true, '', false, 300);
To clip it you need:
$pdf->StartTransform();
$pdf->Rect(100, 100, 200, 300, 'CNZ'); //Clipping mask (CNZ style makes your day)
$pdf->Image('photo.JPG', 50, 50, 300, 400, '', true, '', false, 300);
//this would actually cut off a 50 units a in each direction.
$pdf->StopTransform();
You could crop an image with php , store it as a temp_file pass it to tcpfd and then delete it after the rendering of the pdf was done . Another option would be to use html/css to position a html element over the image but as we all know tcpdf doesn't know too much about css so i don't know if it will work .
I am using the 'twitter for wordpress' plugin to display the last tweet in wordpress. it works fine but needs the username for the twitter account harcoded into the line of code:
<?php
twitter_messages('myaccount', 1, false, false, false, true, true, false);
?>
What im trying to do is replace 'myaccount' with a variable but it doesnt seem to like it.
Im getting the variable I want from another function and works fine but tryin to put it into the twitter code wont work:
<?php
$twitter = contact_detail('twitter');
twitter_messages("'".$twitter."'", 1, false, false, false, true, true, false);
?>
At first the function producing the variable was echoing the value but iv changed it to return it but it has not helped.
Any ideas? Thanks!
Don't do that. You don't need the double quotes. Just say
twitter_messages($twitter, 1, false, false, false, true, true, false);