Printable page with HTML form

greg's picture

He has: 1,581 posts

Joined: Nov 2005

I am making a printable page for customers to be able to print out a form and fill it in by hand, or type it into the HTML form on the site and then print it out (the form action is null).

I would like to instigate a second print page, that is control A4 page one and A4 page two, but I'm guessing this is hard to align and get accurate for everyone as margin settings vary for each person's printer and settings.

I also need some way to stop the scroll bar on textareas, although from searching there seems to be no decent or reliable cross browser solution to this.

The scroll bar on textareas wouldn't be such an issue if I could know where one print page ends and another starts, as I could make the textareas large enough.

I also thought of a PDF file, which might be my best option.

Any ideas or advice?

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

I would vote pdf.

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Hmm, I've since found page-break-after: always; but can't find any info about it being cross browser.

I have never worked with PDF from PHP, how effective is the handling of individual pages? There is still user specific print margins to consider, although I guess they can sort them out themselves.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

PDF is the way to go for making sure the print looks as intended.

As for the margins, a rule of thumb I follow is anything within 3/4" of edges cannot be anything you "need". I have had an inject printer that actually had 3/4" margin at the bottom of the page.

Usually if they have "shrink to fit printable area" turned on, it is still pretty decent, and at least with a PDF, all proportional. You can also recommend to them that they shut off that feature.

I have used two PDF generators, fpdf, and html2pdf which from the docs says it uses a modified copy of fpdf. Be prepared to take time to play around with each, to see what works and what doesn't. But if you do, you can achieve some great results!

(Note on the html2pdf, if you google that, there is a PAID service that if i remember correctly comes up as first result, look for the result on sourceforge)

A hint for just using fpdf: The application we needed it for was to print up certificates for completing online exams. The easiest thing to do was to make a PDF file of the complete certificate EXCEPT for what needs customized (in our case, the name, company, title, date). Then in FPDF you can tell it to start with an existing PDF (which had the graphics/logos/etc) already, and we used fpdf to only add in text. Saved a lot of time! For some reason though, when you do that, the pdf didn't come in proportional, so had to tweak the coords, but in the end was a great looking certificate.

If you go the HTML2pdf route, be prepared to be more limited in your layout compared to just looking at it in a browser. Again, both require reading the docs and playing around but the end result will be worth it!

-Greg

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Cheers. I'll have a gander at them, as the textarea isn't ideal really due to it being able to scroll- printing will lose top or bottom.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I use fpdf and fpdi for printing online certificates. They fill out a form on one page, and fpdf works its magic when they submit it.

Here's what some of the code looks like, maybe it will help you:

<?php
require_once('fpdi.php');
   
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('/var/www/vhosts/mysite.com/cw/CE.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm
$pdf->useTemplate($tplIdx);

// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(0,0,0);


// $x and $y are offset values, if we add an extra line to a file, we can just adjust those
$pdf->Text(65 + $x, 83.5 + $y, $name);
$pdf->Text(52 + $x, 105 + $y, $course_title);
$pdf->Text(82 + $x, 113.5 + $y, $course_cert_number);
$pdf->Text(55 + $x, 122 + $y, $ethics_content);
$pdf->Text(157 + $x, 122 + $y, $total_credit_hrs);
$pdf->Text(74 + $x, 146.5 + $y, $purchase_date);
$pdf->Text(154 + $x, 146.5 + $y, $completion_date);
$pdf->Text(145 + $x, 207 + $y, $provider_date);
$pdf->Text(62 + $x, 241.5 + $y, $WAOIC);

$pdf->Output('CE.pdf', 'D');
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.