Discuss Labels,Pdf,fpdf in the PHP Development forum on Dev Shed. Labels,Pdf,fpdf PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 17
Time spent in forums: 4 h 52 m 28 sec
Reputation Power: 0
Labels,Pdf,fpdf
Labels with PHP,fpdf Issue
Expand Post »
Hello
I have almost completed the code for pdf_labels. However, I am stuck on the fronts. First, the format is not exactly as it should be. Please follow the following URL to see what I am talking about.This is the Label Site As you can see, it starts with label 5 instead of 1, then labels 1 -4 are "doubled up" on labels 21 - 24. Below is the code that the labels currently uses
PHP Code:
function PDF_Label($format, $unit='mm', $posX=1, $posY=1) {
if (is_array($format)) {
// Custom format
$Tformat = $format;
} else {
// Built-in format
if (!isset($this->_Avery_Labels[$format]))
$this->Error('Unknown label format: '.$format);
$Tformat = $this->_Avery_Labels[$format];
}
Posts: 170
Time spent in forums: 4 Days 2 h 34 m 47 sec
Reputation Power: 53
Change this:
Quote:
Originally Posted by aadebayo
PHP Code:
function PDF_Label($format, $unit='mm', $posX=1, $posY=1) {
if (is_array($format)) {
// Custom format
$Tformat = $format;
} else {
// Built-in format
if (!isset($this->_Avery_Labels[$format]))
$this->Error('Unknown label format: '.$format);
$Tformat = $this->_Avery_Labels[$format];
}
To this:
PHP Code:
function PDF_Label($format, $unit='mm', $posX=1, $posY=1) {
if (is_array($format)) {
// Custom format
$Tformat = $format;
} else {
// Built-in format
if (!isset($this->_Avery_Labels[$format])){
$this->Error('Unknown label format: '.$format);
$Tformat = $this->_Avery_Labels[$format];
}
}
Or, better yet, change the if inside an if to simply an elseif.
I'm assuming you have a custom format rather than a built in format. If that is true, your $Tformat variable is getting reset to "$this->_Avery_Labels[$format];" every time your code is run because the if statement is only applying to the first line of code after the statement when you omit the braces.
That may not solve your problem, but it's a start.
Posts: 17
Time spent in forums: 4 h 52 m 28 sec
Reputation Power: 0
Thanks SecurityDavid. I have realised that I posted the wrong code . The code that generates the Label Site is below
PHP Code:
function Add_Label($text) {
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Row full, we start a new one
$this->_COUNTY=0;
$this->_COUNTY++;
if (($this->_COUNTX ==0) and ($this->_COUNTY==0)) {
// End of page reached, we start a new one
$this->_COUNTX=0;
$this->AddPage();
}
}
Posts: 170
Time spent in forums: 4 Days 2 h 34 m 47 sec
Reputation Power: 53
You may have to also post the code that calls this function. The part of this that I think is causing you problems is the COUNTX and COUNTY variables that you have here. As far as I can tell from the fpdf manual, those are not standard functions for fpdf. When I have needed to find and alter the X and Y positions in the past, I typically use the built-in GetX and GetY functions.
Another suggest that may help (I don't really know without seeing the rest) is that when i looked at the label site yesterday, page 2 started correctly because it was generated inside the function. In the function, you have your COUNTX and COUNTY variables set to "0" prior to adding a new page. You should make sure that even though it's a fresh document your new fpdf also has this set.
PHP Code:
$pdf = new FPDF();
$pdf->_COUNTX=0;
$pdf->_COUNTY=0;
$pdf->AddPage();
Posts: 17
Time spent in forums: 4 h 52 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by SecurityDavid
You may have to also post the code that calls this function. The part of this that I think is causing you problems is the COUNTX and COUNTY variables that you have here. As far as I can tell from the fpdf manual, those are not standard functions for fpdf. When I have needed to find and alter the X and Y positions in the past, I typically use the built-in GetX and GetY functions.
Another suggest that may help (I don't really know without seeing the rest) is that when i looked at the label site yesterday, page 2 started correctly because it was generated inside the function. In the function, you have your COUNTX and COUNTY variables set to "0" prior to adding a new page. You should make sure that even though it's a fresh document your new fpdf also has this set.
PHP Code:
$pdf = new FPDF();
$pdf->_COUNTX=0;
$pdf->_COUNTY=0;
$pdf->AddPage();
Thanks SecurityDavid. I have tried your suggestion, but no difference so far.
The code that calls the LabelTest.php script is below
PHP Code:
require('PDF_Label.php');
$pdf = new PDF_Label('3422');
The one calling the Add_PDF_Label with your suggestion is
PHP Code:
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Row full, we start a new one
$this->_COUNTY=0;
$this->_COUNTX++;
if ($this->_COUNTX == $this->_X_Number) {
// End of page reached, we start a new one
//$this->_COUNTX=0;
//$this->AddPage();
$pdf = new FPDF();
$this->_COUNTX=0;
$this->_COUNTY=0;
$this->AddPage();
}
}
Posts: 170
Time spent in forums: 4 Days 2 h 34 m 47 sec
Reputation Power: 53
Try it this way:
PHP Code:
require('PDF_Label.php');
$pdf = new PDF_Label('3422');
//Add the COUNTX and COUNTY resets here, not in the label function.
$pdf->_COUNTX=0;
$pdf->_COUNTY=0;
$pdf->AddPage('L');
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Row full, we start a new one
$this->_COUNTY=0;
$this->_COUNTX++;
if ($this->_COUNTX == $this->_X_Number) {
// End of page reached, we start a new one
$this->_COUNTX=0;
$this->AddPage();
//This is not correct here. Leave this how you had it before. I intended this to go in the script above that calls the function.
//$pdf = new FPDF();
//$this->_COUNTX=0;
//$this->_COUNTY=0;
//$this->AddPage();
}
}
Posts: 17
Time spent in forums: 4 h 52 m 28 sec
Reputation Power: 0
PHP Code:
[QUOTE=SecurityDavid]Try it this way:[PHP]
require('PDF_Label.php');
$pdf = new PDF_Label('3422');
//Add the COUNTX and COUNTY resets here, not in the label function.
$pdf->_COUNTX=0;
$pdf->_COUNTY=0;
$pdf->AddPage('L');
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Row full, we start a new one
$this->_COUNTY=0;
$this->_COUNTX++;
if ($this->_COUNTX == $this->_X_Number) {
// End of page reached, we start a new one
$this->_COUNTX=0;
$this->AddPage();
//This is not correct here. Leave this how you had it before. I intended this to go in the script above that calls the function.
//$pdf = new FPDF();
//$this->_COUNTX=0;
//$this->_COUNTY=0;
//$this->AddPage();
}
}
Thanks a million times for your help, all I had to do is make a minor change and it worked perfectly. I am exceptionally grateful. Below is the new code just in case anyone else needs it. I have applied it to my database record (again I changed it slightly) and it works. Below is the pdf_label code
PHP Code:
function Add_Label($texte) {
// We are in a new page, then we must add a page
$this->_COUNTY++;
if ($this->_COUNTY == $this->_Y_Number) {
// Row full, we start a new one
$this->_COUNTY=0;
$this->_COUNTX++;
if ($this->_COUNTX == $this->_X_Number) {
// End of page reached, we start a new one
//$pdf = new FPDF();
$this->_COUNTX=0;
$this->AddPage();
//This is not correct here. Leave this how you had it before. I intended this to go in the script above that calls the function.
//$pdf = new FPDF();
//$this->_COUNTX=0;
//$this->_COUNTY=0;
//$this->AddPage();
}
}
and below is the code that I applied to the labelTest
PHP Code:
require('PDF_Label.php');
$pdf = new PDF_Label('3422');
//Add the COUNTX and COUNTY resets here, not in the label function.
$pdf->_COUNTX=0;
$pdf->_COUNTY=-1;
$pdf->AddPage('L');
and below is the one that I use for the database values
PHP Code:
require('PDF_Label.php');
// connect to the database
db_connect($mysql['username'], $mysql['password'], $mysql['database'],$mysql['host']);
//// if StartPeriod and EndPeriod set displays all records relevant records//////////////////////////////
$query = "select `members_HouseGroup`.`description` AS `description`,`members_HouseGroup`.`id` AS `housegroupID`,`members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, members_memberType.description as MemberType from ((`members_users` left join`members_memberType` on((`members_memberType`.`id` = `members_users`.`memberTypeID`))) left join `members_HouseGroup` on((`members_HouseGroup`.`id` = `members_users`.`housegroupID`)) ) where (`members_users`.`firstname` = '') or ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) ) and `members_users`.`memberTypeID` > 1 and username not in (select username from members_spouseLink) order by members_users.lastname";
$queryMember = mysql_query("select `members_HouseGroup`.`description` AS `description`,`members_HouseGroup`.`id` AS `housegroupID`,`members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, members_memberType.description as MemberType from ((`members_users` left join`members_memberType` on((`members_memberType`.`id` = `members_users`.`memberTypeID`))) left join `members_HouseGroup` on((`members_HouseGroup`.`id` = `members_users`.`housegroupID`)) ) where (`members_users`.`firstname` = '') or ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) ) and `members_users`.`memberTypeID` > 1 and username not in (select username from members_spouseLink) order by members_users.lastname");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
$numberMembers=mysql_num_rows($queryMember);
// Standard format
$pdf = new PDF_Label('3422');
$pdf->_COUNTX=0;
$pdf->_COUNTY=-1;
$pdf->AddPage('L');
//$pdf->AddPage();
// Print labels
do {
//for($i=1;$i<=$numberMembers;$i++) {
$firstname = $row['firstname'];
$description = $row['description'];
$houseGroup = $row['description'];
if ($houseGroup == "NO Housegroup"){
$houseGroup = "";
}
else
{
$houseGroup = $row['description'];
}
$membersSpouse = mysql_query("SELECT firstname,email,mobilephone FROM members_users where username in (select username from members_spouseLink where spouseUserID='" . $row['username'] . "' and spouseUserID != '' and spouseUserID is not null)");
while (($rowMemberSpouse = mysql_fetch_array($membersSpouse)) != false) {
$spfirstname = $rowMemberSpouse['firstname'];
$countChild = 0;
$memberChildRecord = mysql_query("select `members_users`.`id` AS `id`,`members_users`.`memberTypeID` AS `memberTypeID`,`members_users`.`firstname` AS `firstname`,`members_users`.`lastname` AS `lastname`,`members_users`.`marital_status` AS `marital_status`,`members_users`.`email` AS `email`,`members_users`.`homephone` AS `homephone`,`members_users`.`businessphone` AS `businessphone`,`members_users`.`mobilephone` AS `mobilephone`,`members_users`.`address1` AS `address1`,`members_users`.`address2` AS `address2`,`members_users`.`towns` AS `towns`,`members_users`.`postCode` AS `postCode`,`members_users`.`relationship` AS `relationship`,`members_users`.`username` AS `username`,`members_users`.`status` AS `status`,`members_users`.`marital_status` AS `marital`, group_concat(members_child.cfirstname ORDER BY members_child.dateOfBirth SEPARATOR ' , ') as child from ((`members_users` inner join members_child on (members_child.username=members_users.username) ) ) where (members_child.username = '" . $row['username'] . "' or (members_child.username1 = '" . $row['username'] . "' and members_child.username1 != '')) and ((`members_users`.`memberTypeID` in (select id from members_memberType where housegroupind = 1)) ) or members_users.firstname is null group by members_child.username");
$DueSweepDate = strftime('%d / %m / %Y',$row ['NextSweepDate']);
//get the spouse firstname
//get the children records
while (($rowChild = mysql_fetch_array($memberChildRecord)) != false) {
$numberChild=mysql_num_rows($memberChildRecord);
$leftBrac = "(";
$rightBrac = ")";
$child = $rowChild['child'];
$child = $leftBrac.$child.$rightBrac;
if ($rowChild['child'])$data .= $child . "\n";
}
$email = "email: ";
$phone = "phone: ";
$mobile = "mobile: ";
if ($row['address1'])$data .= $row['address1'] ."\n";
if ($row['address2'])$data .= $row['address2'] ."\n";
if ($row['towns'])$data .= $row['towns'] ."\n";
if ($row['postCode'])$data .= $row['postCode'] ."\n";
if ($row['homephone'])$data .= $phone.$row['homephone'] ."\n";
if ($row['mobilephone'])$data .= $mobile.$row['mobilephone'] ."\n";
if ($spmobile)$data .= $mobile.$spmobile ."\n";
$spmobile = "";
if ($row['email'])$data .= $email.$row['email'] ."\n";
if ($spemail)$data .= $email.$spemail ."\n";
$spemail = "";
if ($houseGroup)$data .= $houseGroup ."\n";
if ($row['memberTypeDesc'])$data .= $row['memberTypeDesc'] ."\n";
$spemail = "";
$query = ($data);
Posts: 3
Time spent in forums: 14 m 27 sec
Reputation Power: 0
reviving this thread
I know this thread is almost a month old, but I found it while searching for a way to do exactly what it appears this thread is covering.
My basic question before I invest alot of time in trying to make this work for me is this...
Is this designed to be able to be used for multiple situations with different avery forms, or is all of the code geared only for a specific application and only for a single form, the 3422 pdf label defined...?
I need to be able to extract mailing information from a mysql DB of product purchases and deliver them to the product fulfillment center in a format that they can simply print them to the avery 5160 label sheet 3 across and 10 up.
I've determined the best, most accurate output would be by creating a pdf and sending it to them to print.
Is this a possible outcome of these scripts, or should I keep looking...
Posts: 17
Time spent in forums: 4 h 52 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by Showman13
I know this thread is almost a month old, but I found it while searching for a way to do exactly what it appears this thread is covering.
My basic question before I invest alot of time in trying to make this work for me is this...
Is this designed to be able to be used for multiple situations with different avery forms, or is all of the code geared only for a specific application and only for a single form, the 3422 pdf label defined...?
I need to be able to extract mailing information from a mysql DB of product purchases and deliver them to the product fulfillment center in a format that they can simply print them to the avery 5160 label sheet 3 across and 10 up.
I've determined the best, most accurate output would be by creating a pdf and sending it to them to print.
Is this a possible outcome of these scripts, or should I keep looking...
Thanks in advance for your response.
Douglas
Douglas
You can customise the file to suit what you need. All you have to do is use the 5160 in place of the 3422 that I used. I do not know if I have answered your question?
Posts: 3
Time spent in forums: 14 m 27 sec
Reputation Power: 0
Quote:
Originally Posted by aadebayo
Douglas
You can customise the file to suit what you need. All you have to do is use the 5160 in place of the 3422 that I used. I do not know if I have answered your question?
Yes, that was basically my question, and the answer I was hoping for.. Now I will take the time to see how I can implement it in my program.
Posts: 3
Time spent in forums: 14 m 27 sec
Reputation Power: 0
Clearly, it is unclear to me
Quote:
Originally Posted by Showman13
Yes, that was basically my question, and the answer I was hoping for.. Now I will take the time to see how I can implement it in my program.
Thanks
OK, after uploading and testing the pdf_label.php and the labelTest.php, I find that I don't really know what I'm looking at, or doing...
My thought was that I could upload those two files and then go to the labelTest.php and it would display on the screen the test page of labels, but that didn't happen..
All I get is a blank page...
I know I'm missing something and it will most likely be very simple, Just not seeing what it is at this point.
In looking over this code in pdf_label, I don't see where some of the variable assignments come from
Part of the problem is trying to understand something that I have never worked with before, using the ($this->) has never been a part of my programming experience.
Any help or direction that you could provide would be greatly appreciated.
Posts: 170
Time spent in forums: 4 Days 2 h 34 m 47 sec
Reputation Power: 53
Quote:
Originally Posted by Showman13
OK, after uploading and testing the pdf_label.php and the labelTest.php, I find that I don't really know what I'm looking at, or doing...
Just so there is not any misunderstanding of what we're doing here, the script above is based on FPDF from here with an add-on from here . This is a customization, not a stand alone script. Please review the documentation on each of these links. Then if you run into problems implementing it, please post your specific issue in a new thread.
Posts: 1
Time spent in forums: 5 m 12 sec
Reputation Power: 0
Did you ever find a solution to producing 5160 pdf labels?
I too am looking to do this
Quote:
Originally Posted by Showman13
OK, after uploading and testing the pdf_label.php and the labelTest.php, I find that I don't really know what I'm looking at, or doing...
My thought was that I could upload those two files and then go to the labelTest.php and it would display on the screen the test page of labels, but that didn't happen..
All I get is a blank page...
I know I'm missing something and it will most likely be very simple, Just not seeing what it is at this point.
In looking over this code in pdf_label, I don't see where some of the variable assignments come from
Part of the problem is trying to understand something that I have never worked with before, using the ($this->) has never been a part of my programming experience.
Any help or direction that you could provide would be greatly appreciated.