Solved

PHP, create multi-page txt file

Posted on 2012-03-21
5
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

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 110

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 110

Expert Comment

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

615 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