Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating print-friendly PDFs using PHP?

Posted on 2014-03-18
1
Medium Priority
?
639 Views
Last Modified: 2014-03-24
I recently created a short PHP script that reads an XLS file, loops through all of it's rows, and then outputs it's contents to a browser:

http://egoselfaxis.net/index.php

The page I'm generating is very fluid at the moment, and is not especially print friendly (when I print using the "CutePDF Writer" print driver .. I get only 2 products per page).

How should I re-format my HTML and CSS (or PHP code) so that I end up with nicely formatted multi-page PDFs that have at least 8-12 items per page (assuming that all of the items/boxes are the exact same size)?  

My PHP code is below:

<?php
	error_reporting(E_ALL ^ E_NOTICE);
	require_once 'excel/excel_reader2.php';
	$data = new Spreadsheet_Excel_Reader("colors.xls");
	$numrows = $data->rowcount($sheet_index=0);
	$startrow = '92';
	for ( $counter = $startrow; $counter <= $numrows ; $counter++) {
		$productid = $data->val($counter,2);	
		if ($productid != '') {	
			echo '<h1 style="clear:left;width:99%;padding:5px;background-color:#FACA43;">' . $productid . "</h1>";	
		}	
		$imgurl = $data->val($counter,16);	
		if ($imgurl != '') {
			echo '<div style="float:left;padding:10px;border:1px solid #333;margin:0 15px 15px 0;text-align:center;width:250px;height:500px;">';		
			echo '<img src="http://www.tasseldepot.com/' . $imgurl . '" /><br />';
			echo '<strong>' . $data->val($counter,12) . '</strong><br /><br />';		
			echo '</div>';	
		}
	}
?>

Open in new window


Thanks,
- Yvan
0
Comment
Question by:egoselfaxis
[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
1 Comment
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39936860
HTML is a semantic markup language; PDF is a page-layout language.  These are not quite as different as fish and bicycles, but they have less overlap than you might think.  I've found good results generating PDF documents with FPDF and TCPDF.  They are a little fiddly at first and require some time to set up the displays, but once you get them working they are consistent and lightning fast.

I have not tested either of them past PHP5.3+ but that aside, I think you would get better results with the PDF if you put the data explicitly on the page, exactly where you want it, in exactly the size you choose.

If you can give us some test data, and a link to the Excel Reader that you're using we might be able to show you a sample script.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

618 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