Solved

PHP, create multi-page txt file

Posted on 2012-03-21
5
250 Views
Last Modified: 2012-03-21
Hello,

I have a list of names and addresses in my db, I would like to be able to output a multi-page txt file so that each name and address in on a separate page.

How do I create a multi page txt file using php?

Thank you,
Matt
0
Comment
Question by:movieprodw
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:Kim Walker
ID: 37749118
Can you provide more detail about what you need? A txt file has nothing but characters and line breaks. It doesn't contain formatting or styles, or layout such as page breaks. Please describe in detail the type of file you wish to generate.
0
 
LVL 1

Author Comment

by:movieprodw
ID: 37749185
Hello,

I am using a label printer and it will print each page as a label so I just need the txt file or even a pdf file (whichever is easier) to create one document that is broken up by pages.

Example:

Username
Birthdate
phonenumber

(NEW PAGE)
Username
Birthdate
phonenumber

(NEW PAGE)
Username
Birthdate
phonenumber

(NEW PAGE)
Username
Birthdate
phonenumber

(NEW PAGE)
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37749249
Consider using the excellent free and open source FPDF class.  It takes a bit of work to get the formatting correct the first time, so build that into your schedule.  Once it is working, it's lightning fast and provides very precise positioning of the printed data.  I've used it for labels, postcards, business cards and baseball rosters.

http://fpdf.org
<?php // RAY_fpdf_hello_world.php
error_reporting(E_ALL);


// DEMONSTRATE THE BASICS OF FPDF


// SOME VARIABLES FOR OUR TESTS (COULD COME FROM DATA BASE, ETC)
$font = 'Arial';
$text = 'Hello World!';

// BRING IN THE PDF THING
require_once('fpdf16/fpdf.php');

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= DIRECTORY_SEPARATOR
. 'RAY_junk'
. DIRECTORY_SEPARATOR
. 'temp_pdf_blue'
. '.pdf'
;
$pdf_file_name
= getcwd()
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A BLUE BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 16);
$pdf->SetFillColor(  0,   0, 255);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Blue PDF</a>';



// START OVER FOR A NEW PDF
unset($pdf);
echo PHP_EOL . "<br/>";

// SYNTHESIZE THE PDF FILE INFORMATION
$pdf_file_link
= DIRECTORY_SEPARATOR
. 'RAY_junk'
. DIRECTORY_SEPARATOR
. 'temp_pdf_red'
. '.pdf'
;
$pdf_file_name
= getcwd()
. $pdf_file_link
;

// DO THE HELLO WORLD EXERCISE IN WHITE ON A RED BACKGROUND
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont($font, 'B', 16);
$pdf->SetFillColor(255,   0,   0);
$pdf->SetTextColor(255, 255, 255);
$pdf->Cell(40, 10, $text, 0, 2, 'L', TRUE);

// WRITE THE PDF TO DISK
$pdf->Output($pdf_file_name, 'F');

// PRESENT A LINK
echo '<a target="my_PDF" href="' . $pdf_file_link . '">Red PDF</a>';

Open in new window

0
 
LVL 1

Author Closing Comment

by:movieprodw
ID: 37749423
Already have it up and running, as usual you have saved me lots of time, thank you Ray!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37749680
Thanks for the points, and best of luck with your project, ~Ray
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.htaccess file settings 4 35
Error installing extension Linux 4 30
PHP json decode 9 0
How to fetch your row in php 14 0
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now