Page 2 of 2

Posted: Thu Dec 08, 2005 5:50 pm
by Bill H
The pdf also eliminates the need for clicking a "next" button for each page. Mulit-page pdf docs are printed in one step.

I've never used the fpdf class that onion2K referenced, but it certainly looks clean and easy.

Posted: Sun Dec 11, 2005 11:18 am
by LordMerlin
FPDF seems to be able todo what I want to do. The only problem is, I can't figure out exactly how. They have this one example, http://www.fpdf.org/en/script/script29.php, which can use Avery type labels, which to a great extend meets my requirements. The only problem is, uses the same font and font size for all the text in the label, and I'm not quite sure yet how to get it to pull label types from a MySQL DB. This way I can have a form that the user can choose his label type from, and print it out.

Any suggestions? Or does anyone have some samples for me how to be able to use MySQL data to print to AVERY type labels, which should also be stored in a MySQL DB? If I can't get something to "draw / design" the labels with, at least I can get the users to add / modify labels with a form

Posted: Sun Dec 11, 2005 1:27 pm
by John Cartwright
This sounds like a fantastic oportunity to use Ajax. I would say a form is the go here, and when an option is selecting, lets say for font or label size then it is dynamically re-drawn as the option is selected as a realtime preview.

Posted: Sun Dec 11, 2005 3:42 pm
by LordMerlin
Ok, wait. I don't want to learn each new trick there is to learn. No offense, but as it is, I'm having a hard enough time already getting fpdf to work. To learn Ajax now, in order to learn how to work with fpdf is rather time consuming, which I don't have much of at this stage. I have had a look @ Ajax b4, and I don't quite think it's viable to ue it at this stage, though I am thinking of using it at a later stage. Thanx for the info though :)

Any other suggestions?

Posted: Tue Dec 27, 2005 2:44 pm
by LordMerlin
Jcart wrote:
you say PDF would work great for this, please elaborate, if you don't mind.
It is great because you can control everything from exact positioning of the elements (impossible to do in a browser because there are too many variables to consider, such as resolution).
Wouldn't that put extra load on the server?
Of course it will, to what extent I am unsure. There are several weighing factors, such as how many hits and concurrent pdf generations you have going simultaneously. Anything you add to your page is going to increase server load in one way or another :cry:
And if I create a PDF file to be printed, then the client would need a PDF viewer to open, and the print it, right. Is there a way of the PDF file being printed automatically, on the fly?
Right. But remember we are trying to avoid printing from the browser because lots of bad things can happen there. Labels could be split in half at the page breaks, etc. I really don't see the inconvinience of this, it is one minor step of a program being automatically opened, and clicking print from there instead of the browser.
onion2k wrote:Re automatically printing: Sure.. look at the 'autoprint' example on this page: http://www.fpdf.org/en/script/script36.php
Now you have no excuse ;)


But this still doesn't answer my other question (unless I don't understand all your answers). Is there a way for the user to design the label layout? Or will it have to be pre programmed into the script? What happens if they want to change the layout, to let's say bigger labels (meaning there will be less labels on the page), or they want to print to a label printer, which has a single row of labels, instead of an A4 sheet with either 2 / 3 / colomns with labels.
If you take some time to look at the functions for modifying and creating PDF documents, you'll find it is extremely customizable. I have been using PDF generation to generate reports with several different optional templates, store in the database. Having a couple saved templates would be ideal and allow the user to choose, but the power comes in since you could allow users to select the dimensions, etc.

Now the more user modifiable you want this the more complex it's going to get, obviously. Your going to have to make several calculations on how many labels you can fit on a page (which shouldn't be too dificult) without having labels overlapping or whatever. I would keep it simple by offering a dozen or so different templates each with different dimensions, that way you can avoid all the hassle in the first place.
Is this getting too technical? Kbarcode has a MySQL database with plenty Avery type labels, which I'm sure I can use as a base for the label sizes? But let's say they get custom size labels which they want to print on, I should have a way of them adding a label into the system. How would I be able to work around that? To me it sounds like I would need to make my HTML tables dynamic, but how? Somehow I would then need to let the system know that it needs to print 2 rows of labels, 50mm from either side, 20mm apart, and 10 above the previous one. Does HTML know about METRICS, or does it only work with pixels?
Back to my last point, this can get overly complicated with how you are wanting to approach this. First of all, you are not using html, you are creating shapes and lines with positions on the sheet. Have a read of the pdf library function.
Hi cart

I had a look at fpdf, and failed :(

I have some info in a MySQL DB, which I tried to print via a A4 PDF document, but couldn't get it to work. The user gets a form to fillin, providing info such as papersize (A4, letter, A5, etc), number of labels accoss, number of labels down, label width and hight, etc etc. My problem is, I can get it to print some labels on one page, but the monent I try and print say a 100 labels, I my script seems to use all my PC's CPU. I have 512MB Ram, on a LGA775 PIV 2.5Ghz, thus my machine should handle it?

I also can't seem to tell it to go on to the next page when it reaches the bottom of the page. The last few labels seem to get "clipped of"

Any suggestions?

Code: Select all

include_once("classes/fpdf.php");
define('FPDF_FONTPATH','classes/font/');



// Creates new PDF Document Instance
$pdf=new FPDF('P','mm',$_GET['paper_size']);
//$pdf->SetDisplayMode(fullpage);
// Add the PDF page to be displayed.
$pdf->AddPage();
//Begin with regular font
if (empty($_GET['font_size'])){
	$font_size = 12;
} else {
	$font_size = $_GET['font_size'];
}

$pdf->SetFont('Arial','B',$font_size);
$pdf->SetAutoPageBreak('on',$_GET['t_gap']);
$pdf->SetTopMargin(5);
$pdf->SetLeftMargin(0);



$a = $row['name'];
$b = "Expires: ".$row['expire'];
$c = "Take ".$row['dosage'];
$d = "No ".$no." / Pages ".$pages;
//$e = $_GET['l_gap']." / ".$_GET['t_gap']." / ".$_GET['width']." / ".$_GET['height']." / ".$font_size." #".$i." #".$v;

$width =$_GET['l_gap'];
$height =$_GET['t_gap'];


for($i=1; $i<$_GET['h_number']+1; $i++) {

	for ($v=1; $v<$_GET['v_number']+1; $v++) {
	
		$pdf->SetXY($width,$height);
		$pdf->MultiCell($_GET['width'], $_GET['height']/10 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'L');
		$pdf->Write(5,$v);
		
		$Xpos = $width+$pdf->GetX();	
		$width = $Xpos+$_GET['width']+$_GET['h_gap'];
	
	}		

$width = $_GET['l_gap'];
$Ypos = $pdf->GetY();
$height = $Ypos+$_GET['h_gap'];
}


		
$pdf->Output();

Posted: Tue Dec 27, 2005 2:57 pm
by LordMerlin
Jcart, do you by any change have such a sample for me?

I tried some AJAX stuff, and it's greek to me :) I just need something where the user can say how many labels are horizontal and vertical, what size they are, how big the gaps are between (height and width), and choose the paper sizes