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...
Related
When I hide header with
$this->setPrintHeader(false);
it still leaves an empty gap (space) from the top. How to remove the gap so the body would appear from the beginning of page?
EDIT1: this the prestashop function I use
public function writePage()
{
$this->SetTopMargin(-50);
$this->SetHeaderMargin(-55);
$this->setPrintHeader(false);
$this->SetFooterMargin(21);
$this->setMargins(10, 50, 10);
$this->SetAutoPageBreak(true, 40);
$this->AddPage();
$this->writeHTML($this->content, true, false, true, false, '');
}
EDIT 2: this combination works for me
$this->setPrintHeader(false);
$this->SetTopMargin(0);
$this->setMargins(10, 20, 10); <- Now I can set margins as I want
Apart from not printing the header you also need to set margins to 0, so in this case:
$this->SetTopMargin(0);
Note that you can manipulate the margin of the header too with $this->SetHeaderMargin();
Edit: you can use negative values too.
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?
I am using TCPDF to create simple pdf document.
I am creating a page and adding link using below code
$pdf->addTOCPage();
$link = $pdf->AddLink();
$pdf->SetLink($link, 0, -1);
Now link is set successfull.But to navigate to that page what should I add ?
I tried below code , but it does nothing,
Return to TOC
// Create a fixed link to the first page using the * character
$index_link = $pdf->AddLink();
$pdf->SetLink($index_link, 0, '*1');
$pdf->Cell(0, 10, 'Link to INDEX', 0, 1, 'R', false, $index_link);
http://www.tcpdf.org/examples/example_045.phps
update -
refer to this function addHtmlLink() in tcpdf library.
You can add a internal link through this
$pdf->addHtmlLink('#'.$index_link, 'hello');
where 'hello' begin the name of anchor and and first param being identifier to the link.
In your case
$pdf->addHtmlLink('#'.$link, 'Whatever you like to name it');
$html = 'link name';
$pdf->writeHTML($html, true, false, true, false, '');
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');
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);