DarkHouse
2011-05-25
I'm under a lot of pressure to get this PDF working, I'm a couple days overdue
actually. All I'm trying to do is create a pdf that has some ID cards to be
printed. I am generating these cards on the fly. I've created 2 graphics, one
for an individual card that I tried looping through and adding to the page but
that didn't work. It ended up putting each graphic on its own page. So I tried
playing around with the Y coordinate, and it seems like I can only fit about 4
inches before it goes to the next page, but I am using LEGAL size.
So then I tried creating one big graphic to use as a template that already has
the cards laid out, but although that graphic is 7"x13" it shows up only about
4 inches tall.
What I'm looking for is someone to just guide me through the quickest and
easiest way to get this done. I'm obviously missing something just trying to
get images to show up properly, but then I'll also need to overlay text on
those images, and each student's photo.
Here's my current code, although it's a little messy with code commented out.
Also, I'm using CodeIgniter, but that shouldn't make a difference.
$this->load->library('tcpdf'); $this->tcpdf->SetSubject('ID Cards'); $this->tcpdf->SetFont('helvetica', 'B', 8); $this->tcpdf->AddPage(); //$template1 = $this->tcpdf->startTemplate(8.5, 14); $this->tcpdf->Image('images/id_card_bg2.jpg', 0.75, 0.5, 7, 13, 'JPEG', '', 'B'); //$this->tcpdf->endTemplate(); //$this->tcpdf->printTemplate($template1, 0, 0); $i = 0; $student_ids = $this->input->post('students'); foreach($student_ids as $id){ $student = $this->student_model->get($id); //$this->tcpdf->Image('images/id_card_bg.jpg', 0.5, $i*2.2, 7, 2, 'JPEG', '', 'B'); $this->tcpdf->Cell(0, 0, $student->first_name.' '.$student->last_name); $i++; } $this->tcpdf->Output('example_001.pdf', 'D');
Thanks in advance for any help. It's greatly appreciated.
Nicola Asuni
2011-05-25
The "quickest way" is to ask a custom professional module to info@tecnick.com
Alternatively I suggest you to carefully read the documentation and check the
default examples.
DarkHouse
2011-05-25
I had been through the docs and all over google, however I found this example
that I is similar to what I'm trying to do http://www.tcpdf.org/examples/exam
ple_062.pdf so I tried the
following:
$this->load->library('tcpdf'); $this->tcpdf->SetSubject('ID Cards'); $this->tcpdf->SetFont('helvetica', 'B', 8); $this->tcpdf->AddPage(); $i = 0; $student_ids = $this->input->post('students'); foreach($student_ids as $id){ $student = $this->student_model->get($id); $template1 = $this->tcpdf->startTemplate(7, 2); $this->tcpdf->Image('images/id_card_bg.jpg', 0, 0, 7, 2, 'JPEG'); $this->tcpdf->Cell(0, 0, $student->first_name.' '.$student->last_name); $this->tcpdf->endTemplate(); $this->tcpdf->printTemplate($template1, 0.75, 0.5 + $i * 2.2, 7, 2); $i++; } $this->tcpdf->Output('example_001.pdf', 'D');
But I get the same problem as I originally had where it puts each card on its
own page (although my text is over top of my image, so that's a step forward).
With this logic, the only thing not working as expected is the Y position of
the cards. They should be be 0.5 inches from the top (margin) plus 2.2 inches
times $i which would separate them evenly and allow me to add some nice crop
marks.
If I change the Y coordinate to just 0.5 + $i for testing it ends up showing
the first 2 cards on the first page, the 2nd card being only 1 inch from the
top of the first one so they overlap, and then the 3rd one is at the top of
the 2nd page by itself, and the 4th is at the top of the 3rd page by itself.
I'm obviously missing something. Why can't I get my cards to fill the page,
why do they keep creating new pages. It's like threshold for flowing content
to the next page is up way too high (or low...), I can't seem to put anything
past 4 inches of the page or else it'll create a new page. Is that maybe what
the problem is? Is there a content threshold I can overwrite?
I'm so close to being done this project, this is the last thing that's causing
a problem. I appreciate any help. Thanks.
DarkHouse
2011-05-25
Ok, I found SetAutoPageBreak and set it to false, that seems to have solved my
problem. Still though, why would it break the page after 4 inches when it's
set to LEGAL?