Hello to all!
I have an online manual (developed in php)that my company would like to revise for printing purposes. What I need to do is have this manual setup to include page numbering on the printed version so the instructor can reference pages during training sessions.
They have expressed something similar to the way MS Word sets up up page numbering.
I know I could manually set up the page numbers, but everytime the manual gets updated, I would have to re-number the pages.
Any ideas on how to set this dynamically using php?
Your thoughts are greatly appreciated!

Dani AI

Generated

A few practical ways to get stable printed page numbers for the manual (building on ’s idea of a single output and ’s PDF pointer). Two approaches are most useful in practice: a quick client-side print stylesheet (easy but fragile across browsers), or server-side HTML→PDF generation (more work up front, reliably consistent page numbers and "Page X of Y").

A client-side print CSS can hide nav, force section breaks and attempt page numbers with CSS counters. Example print CSS (add to your print stylesheet):

@media print {
  @page { margin: 20mm; }
  h1 { page-break-before: always; }
  .avoid-break { page-break-inside: avoid; }
  .print-footer { position: fixed; bottom: 0; right: 0; font-size: 11px; }
  .print-footer::after { content: "Page " counter(page); }
}

This method relies on browser support for paged-media features and margin-box counters, which is inconsistent — useful for quick testing but not guaranteed to produce "Page X of Y" across all printers/browsers. (devdoc.net)

For a dependable result, assemble the whole manual server-side and render to PDF. Tools that work well: wkhtmltopdf (command-line WebKit-based renderer), dompdf (PHP library), and commercial engines like Prince for high-quality paged output. Server-side PDF generation gives precise pagination, reliable headers/footers, and programmatic "Page X of Y" footers you can control. Example (simple wkhtmltopdf flow):

// build full HTML for the manual
file_put_contents('/tmp/manual.html', $html);
exec('wkhtmltopdf /tmp/manual.html /tmp/manual.pdf');
header("Content-Type: application/pdf");
readfile('/tmp/manual.pdf');
exit;

Use dompdf if you prefer pure-PHP rendering; use wkhtmltopdf or Prince when CSS fidelity and complex layouts matter. (wkhtmltopdf.com)

Quick practical tips: embed images with absolute URLs or enable remote fetching in your PDF tool, add CSS classes like .page-break to control where new pages start, hide on-screen chrome with @media print, and test the exact printer/browser combo instructors will use. If exact "Page X of Y" is required, choose server-side PDF generation — it avoids browser inconsistencies and gives you one-maintenance source for numbered printouts.

Recommended Answers

All 13 Replies

how exactly is the manual set up. Is it a webpage; is it seperate document, what?

can you give me link to it so i can see what we're working with?

Currently the manual is set up as both separate pages and a "main page" for each section that flows from one sub-section to the next. I used anchors within this page to navigate.
From the Table of Contents, you can either select the "Main Page" of the section or go directly to a sub-section page. Basically it is a "webpage(s) at this point.
I know this sounds a bit confusing, but I did not initially set this up and I would like to set this up in a fashion that would require as little maintenance as possible once completed. (i.e. the page numbering). My thoughts were to store the entire manual contents within a table and dynamically produce both content and the page numbering.
Does this sound like a reasonable way to proceed with this?

what i would do is have one php page process the entire manual. Other pages that hold the data will be included base upon the varibles in the url. also, what i would do is give a link to a word document of the entire manual that could be downloaded and printed by them. this would solve the page numbering problem. if this isn't something you can do i can always think of a different way. i also can make the php page to process the manual if you need me to, its pretty easy.

what i would do is have one php page process the entire manual. Other pages that hold the data will be included base upon the varibles in the url. also, what i would do is give a link to a word document of the entire manual that could be downloaded and printed by them. this would solve the page numbering problem. if this isn't something you can do i can always think of a different way. i also can make the php page to process the manual if you need me to, its pretty easy.

Hey many thanks for the thoughts...
Can you give me a bit more info on how you would process the entire manual from one php page? As in a function of some sort...maybe from the table of contents page I coud have a printing function that would either
A -> print the manual in MS Word format (which may not be an option) or
B-> loop through the URL variables for printing
Any more insight would be greatly appreciated...you at least you got the thought process rolling.
;)

how is your manual broken down. TABLE OF CONTENTS > SECTIONS > ?. After i know this information i will get to work on the code for you.

Maybe this will help you...I use it for generating a parts book from mysql and our employee handbook. It's pretty nice.

http://www.ros.co.nz/pdf/

how is your manual broken down. TABLE OF CONTENTS > SECTIONS > ?. After i know this information i will get to work on the code for you.

The manual is broken down as so:

Table of Contents (no page number for this)

Introduction
Physical Basics
BASIC PRINCIPLES
Balance/Defensive Stance
Pivot
The Front Lift
ASSISTS
One Person Cross Grain Hold
Two Person Cross Grain Hold
Shoulder Loop/Ankle Compression
2 on 1
GRABS
One Handed Parallel Grab - Punch Out
ect...
The bolded titles are the sections and the items below are the content pages for within that section
I appreciate your help on this one...and I am also looking at the information that jbcrawford sent.
For now I am busy typing the darn thing up again..

i have almost finished the code. you can view it on my server; . please tell me what you need me to fix or what you want differently. all of the text formatting can be changed by you. the code works by using txt files in certain folders. all you have to do is name the file as the title ex. (One Person Cross Grain Hold.txt), type some information into the file and the code will do the rest. i am still working on the printing part.

i have almost finished the code. you can view it on my server; . please tell me what you need me to fix or what you want differently. all of the text formatting can be changed by you. the code works by using txt files in certain folders. all you have to do is name the file as the title ex. (One Person Cross Grain Hold.txt), type some information into the file and the code will do the rest. i am still working on the printing part.

Thanks!
No changes thus far..just a quick question...can the text file contain images and html code?
nice job so far though

yes, think it can contain html code but i'll have to check. i'll make sure it can if it doesn't work. i also think php will work inside the text files as well. I will have to back with about these two things though. i cannot check on it until 3:00pm today.

also the folders are set up this way:

Foldername:introduction -
Contains:
Introduction.txt
Physical Basics.txt

Foldername: basic principles -
Contains:
Balance Or Defensive Stance.txt
Pivot.txt
The Front Lift.txt

Foldername: assists -
Contains:
One Person Cross Grain Hold.txt
Two Person Cross Grain Hold.txt
Shoulder Loop And Ankle Compression.txt
2 on 1.txt

Foldername: grabs -
Contains:
One Handed Parallel Grab - Punch Out.txt

pretty much each section is a folder. then anything else with that section is a txt file with information. i thought this info would be helpful so you could start setting it up. from what i have on the printing aspect; try , this includes all the files on one page so it can be printed. i am still working on the numbering part, any ideas?

for page printing maybe a loop through of the section/contents???

html can be used in the text files. also, the print thing works but i don't know about page numbering. i have no idea how much text is printed off before a new page number is required.

WOW!! This is exactly what I'm looking for, but the links above are dead and my site uses aspx. Could anyone point me to a more recent version, please?

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.