i want to create a text report and i have use this coding:-

<?php
$f=fopen("c:\amit.txt", "wb");

// adding header
$text="\n Your text to write \n ".date('d')."-".date('m')."-".date('Y')."\n\n";
fputs($f, $text);
fclose($f);
?>

which results me some thing like when i open it in windows [i.e my computer->c drive->mit.txt] :-

[]Your text to write[]09-09-2012[][]

but i want it like this

Your text to write
09-09-2012

and in fanfold paper size 14" * 12"
as i have a huge data to create a report for ex payslip of all employee in my company

plz help me

Dani AI

Generated

Thread summary and practical options (short, actionable)

This thread shows the common gap between producing plain text and controlling how it prints. moved a VB6 workflow to PHP and saw literal characters instead of visible line breaks in Windows; pointed toward Windows-style endings and mentioned using print/CSS for page size. Two useful, practical approaches follow: plain-text with form-feed page separators for simple printing, or generating a fixed-size PDF for reliable 14"×12" output.

Plain-text, Notepad-compatible output

  • Produce lines joined with the platform EOL token and append a form-feed character between pages. Write the file in one atomic call (or with an exclusive lock) so large runs don’t get corrupted. Plain text has no page-size metadata; page breaks are handled by the viewer/printer (some viewers ignore form-feed). Example PHP pattern:
$lines = [
  'Company Payroll Report',
  'Generated: ' . date('Y-m-d'),
  '---',
  'Employee: John Doe',
];

$content = implode(PHP_EOL, $lines) . chr(12);
file_put_contents('C:\\amit_report.txt', $content, LOCK_EX);

PDF/HTML approach for exact 14"×12"

  • For precise physical sizing, generate a document that carries page-size and margins (PDF or HTML+@page). A PDF library lets the script set a 14×12 inch page, choose a monospaced font, and control line height. That guarantees the printer receives the correct paper size and produces consistent 60–75 lines per page. Example outline with an FPDF-style library:
require 'fpdf.php';
$pdf = new FPDF('P', 'in', [14,12]);
$pdf->AddPage();
$pdf->SetFont('Courier','',10);
...
$pdf->Output('F','C:\\amit_report.pdf');

Sizing note and caution

  • Lines-per-page ≈ (usable inches × 72) / font‑points. For example, 11 usable inches with 12pt ≈ 66 lines. Test font, margins and the target printer/driver — some drivers require a custom paper profile for fanfold sizes. Plain text + form-feed is simplest for legacy printers; PDF gives the most predictable, production-ready results.

Recommended Answers

All 7 Replies

Member Avatar for Member #120589

Not sure about that, but you can set dimensions in a Print CSS file. You can set page breaks etc, but I'm not sure that it can be set dynamically, unless you use js.

sir very very thanks for replying me but as i am a very fresher in this feild plz give me some sampal js and print ccs coding for line break / set page breaks etc so that i can get my output file [amit.txt] like

Your text to write
09-09-2012

instant of

[]Your text to write[]09-09-2012[][]

when i open it in windows [i.e my computer->c drive->amit.txt]

kind att. plz
currently i am using visual basic 6.0 and i use char(12) function for line break and char(13) function for page break
and
i want to switch this program vb 6.0 to php

i think i have made myself clear to u.

plz help me to come out of it

plz....................

Does this help

$text="\r\n Your text to write \r\n ".date('d')."-".date('m')."-".date('Y')."\r\n";

thanks urtrivedi, its works for line break but at last i want something for page break

Member Avatar for Member #120589

I'm sure you can Google 'css page-break', can't you?

I am not sure how you can add page break in plain text file. I think its dependent on software you use to open file like notepad/wordpad/word etc.

dear friends , i got my solutions by using \r\n for line break and \n\f for paze break
but remimber that report should contains 60 to 75 nos of line per page depending on font/fonte size u use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.