473,756 Members | 4,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

address labels using php | mysql | fpdf

hi,
i'm looking for some script which would export address labels from a
mysql db to pdf ...

There's an exapmle, but i'm not able to convert it for using with
mysql ... can anybody help?

THX a lot

Martin :)
=============== =============== ============
Author: Steve Dillon (208.241.182.---)
Date: 02-20-02 19:35

Hi,
I made a routine to print address labels I thought I would share. Its
for a very common 2 5/8" wide x 1" tall address label found in the
States. To use you need to set the page size to 8.5" x 11" and have
the user UNCHECK "Fit to Page" when printing.

<?php
function odbc_fetch_arra y($res) {
$row = array();
$result = array();
if ($result = odbc_fetch_row( $res)) {
$nf = odbc_num_fields ($res)+1;
for($count=1; $count < $nf; $count++) {
$field_name = odbc_field_name ($res, $count);
$field_value = odbc_result($re s, $count);
$row[$field_name] = $field_value;
}
return $row;
}
}
// Prints to an Avery 5160 label sheet which is a label
// 2 5/8" wide by 1" tall, they are 3 accross on a page
// and 10 rows per page. (30 per page). The upper left
// corner is label(0,0) The X co-ord goes horizontally
// accross the page and Y goes vertically down the page
// Left/Right page margins are 4.2 MM (1/6 inch)
// Top/Botton page margines are 12.7 MM (.5 inch)
// Horizontal gap between labels is 4.2 MM (1/6 inch)
// There is no vertial gap between labels
// Labels are 66.6 MM (2 5/8") Wide
// Labels are 25.4 MM (1" ) Tall
function Avery5160($x, // X co-ord of label (0-2)
$y, // Y co-ord of label (0-9)
&$pdf,
$Data) // String w/ line breaks to print
{
$LeftMargin = 4.2;
$TopMargin = 12.7;
$LabelWidth = 66.6;
$LabelHeight = 25.45;
// Create Co-Ords of Upper left of the Label
$AbsX = $LeftMargin + (($LabelWidth + 4.22) * $x);
$AbsY = $TopMargin + ($LabelHeight * $y);

// Fudge the Start 3mm inside the label to avoid alignment errors
$pdf->SetXY($AbsX+3, $AbsY+3);
$pdf->MultiCell($Lab elWidth-8,4.5,$Data);

return;
}

function PrintAddressLab els($SelectStmt )
{
global $cnx; // database conneciton in odbcinc.php

$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial ','B',10);
$pdf->SetMargins(0,0 );
$pdf->SetAutoPageBre ak(false);

$cur = odbc_Exec($cnx, $SelectStmt);

if (!$cur) {
echo "Database Error";
return;
}

$x = 0;
$y = 0;
while (TRUE) {
if ($row = odbc_fetch_arra y($cur) ) {
$LabelText = sprintf("%s\n%s \n%s, %s, %s",
$row['MailName'],
$row['Address'],
$row['City'],$row['State'],$row['Zip']);
Avery5160($x,$y ,$pdf,$LabelTex t);

$y++; // next row
if ($y == 10 ) { // end of page wrap to next column
$x++;
$y = 0;
if ($x == 3 ) { // end of page
$x = 0;
$y = 0;
$pdf->AddPage();
}
}
} else {
// Error quit printing
break;
}

}
$pdf->Output();
}

?>
Jul 16 '05 #1
0 19899

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11617
by: Eric Linders | last post by:
Hi, I have customer contact information in a MySQL DB. The standard stuff: first name, last name, city, state, zip, etc. I'd like to write a PHP script that will take a customer ID range (e.g., customer 10000 - 11000) and stick those into an MS Word document, plain text document, or a PDF (any of the three will work). The key is that each record has to have a page break after it so that
1
1788
by: Chris B | last post by:
Does anyone know of a way in VB.net, to implement the following functionality in printing address labels. Allowing the user to select from which location on a stadard address label sheet (Avery 5160) they want to begin there printing from. The address labels are printed using Crystal Reports and currently always begin from the default location.
1
1487
by: Frank | last post by:
Hello, I hope this is the correct group to ask this question. I am fairly new to programming, but have a gut feeling this is a pretty easy problem to overcome. I hope I can explain the problem clearly enough. Using VB.Net 2003 and MySql db. I have a table (mySql) with the following fields: main_category| category| sub_category| answer|date
3
30334
by: K. | last post by:
Hello! Could you be so kind and help me with one problem I have. I would like to put an image into the table while creating PDF file. I use fpdf class (www.fpdf.org). I cannot find any example in internet and group archieves and www.fpdf.org page.
29
15450
by: FredBear | last post by:
I am just coming to grips with php, Dreamweaver and MySQL and I want to make a facility available for the members of the group I am creating my web site for. I want them to be able to print-out a list of address labels, using standard Avery labels, on their home PC's using the data from my MySQL tables. I am not yet sufficiently au fait with php to manage to code it myself so I wondered if anybody knew of any Dreamweaver extensions, add-ins...
6
5479
by: Steve | last post by:
been gleening the user docs for fpdf. there's one simple example for using the image function. i can't seem to get it to work. has anyone else had problems with this, and if so, what did you do to diagnose and fix the problem? tia, me
5
7809
by: cappieins | last post by:
Hi, i've got a problem using PHP FPDF library to create PDF files send inline to a browser window. The created PDF file opens correctly in the browser (IE 6), but if I want to save it to my local disk, there is not automatically the filename used I passed
1
2781
by: Sergei Riaguzov | last post by:
Hi, I'm having problems with fpdf v.1.1 used on the site - it doesn't open all PDFs with setSourceFile it says something about "missing xref headers". So I tried to install a newer fpdf version the v.1.53. And now the setSourceFile method of the previous fpdi class (now it is called FPDF) is gone. What should be used instead of it?
5
1405
by: Steven Nagy | last post by:
Hiyas Our app has a search field where you can select a country drop down and then enter some search criteria that is address based. We want the labels on the search form to change based on what country you select. For example, if I select UK, it might ask for District and Borough (sp?). Whereas if I select Australia, I need it to say State and Postcode. For the US it might say Zip instead. I figure best way is to store all these...
0
9462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.