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?
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.
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 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');
With PHP application, I have to generate single PDF documents, from set of images.
Which is best way to achieve this? Can I use TCPDF library, and can you give me some example?
The easiest way is to use TCPDF (http://www.tcpdf.org) and set the images as full background as on the example n. 51.
For example:
// disable auto-page-break
$pdf->SetAutoPageBreak(false, 0);
// set image 1
$pdf->AddPage();
$this->Image('image_demo1.jpg', 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
$this->setPageMark();
// set image 2
$pdf->AddPage();
$this->Image('image_demo2.jpg', 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
$this->setPageMark();
// ...
you can use dompdf.You can find a copy of the original documentation at this link
I don't know your requirements but ImageMagick could probably do the trick. I believe that they also have a php wrapper available for all the image manipulation/conversion functions.
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 .