PDA

View Full Version : creating a printable graphic from PHP output


dank
06-27-2002, 01:03 AM
This question could fit a few different forums, depending on the method taken to tackle the problem. Ok, here's the situation (said in my best Will Smith voice) :

I've got a PHP script that outputs a coupon, the idea being that it can be printed off and taken to wherever it's intended to be used. I figured I'd pretty it up a bit by adding a dashed line (long dash, short dash) around the perimeter, accomplished by using a repeating graphic as table backgrounds within outer cells. Looks good on screen, but the dashed lines don't print... I've seen this with other repeating graphics, such as page backgrounds and certain stretched images. Seems printers ignore them. If anyone can think of a way around that, then this becomes an HTML question, not a PHP one...

I could resort to using a single, non-repeating image of a fixed size for each edge of the dashed line, but that would rely on the text and graphics within the coupon not exceeding a maximum size (risky considering the difficulty in ensuring font sizes from one browser to the next).

So, I'm thinking something more dynamic might be in order, possibly PHP's GD or PDF libraries. I don't believe we have PDF support built-in on the FutureQuest servers, do we? It would be a dream come true if the GD functions (what's GD stand for, anyway?) allowed a way of reading file output into a graphic created on the fly, but it appears only existing images can be read in.

There is the imagesetstyle() (http://www.php.net/manual/en/function.imagesetstyle.php) function that can create dashed lines, so that might be a good starting point, albeit a rather complex one for the intended result. I'm still unsure of whether or not that would work, though. Wouldn't I still need to know the size of the resulting image in order to work with perimeter coordiantes for the lines? That would seem to require mapping out areas of the coupon that cannot be spilled over by text, but at least I could graphically ensure font consistency...

Any other suggestions? I could put an HTML snapshot of the coupon up on the server, if it would help people to see what I'm working with.

Dan

BenV
06-27-2002, 08:12 AM
In IE there is an option to "Print background colors and images" which is why sometimes they get ignored when printed. So, unfortunately I think that your "create an image" solution is not reliable.

You could, however, follow this route and include an explanatory note to user that they must have image printing on, along with simple instructions on how to do it.

Just my $0.01
---
BenV

dank
06-27-2002, 12:20 PM
In IE there is an option to "Print background colors and images"
Ah, I hadn't seen that, thanks. That does seem to work nicely, although it's a better solution for my own browsing than for expecting others to view/print the coupon properly.

Of course, it seems to display such images even worse in Netscape (only tested on 4.7x), so that may not be such a good solution...

Dan

Matt
06-27-2002, 06:05 PM
If all you're printing is text, then you could roll your own solution. That is, create 10x10 pixel bitmaps for each letter, then have PHP dynamically load the graphic corresponding to each letter of the coupon. This would ensure the static images along the outside of the coupon matched the dimensions of the letters, irrespective of browser.

A simpler solution: use CSS to set text to justified. Then, create the borders of your coupon using text "- - - - - - - - -" for top and bottom using "|". The browser should expand the dashes to fill the table. For a more "coupon-like" effect, you could make them bold and a different color.
-Matt

dank
06-27-2002, 06:47 PM
Thanks for the suggestions. If I'm not mistaken, the first one assumes a fixed amount of text (won't be the case), and the second would require some way of making one pipe character ( | ) fit on each text row for the side borders, which would be rather tricky with graphics also within the coupon.

Is that not what you were thinking?

Dan

Matt
06-27-2002, 09:39 PM
I didn't realize you also wanted to put graphics in the body of the coupon. Would CSS let you specify dashed lines for table borders? If it did, you might be able to just put a table around the whole thing.

dank
06-27-2002, 09:49 PM
Yep, just trying to make this simple little project as complicated as possible. :) Of course, the client will probably be thrilled just that the system is dynamic now and not care what it looks like...

Would CSS let you specify dashed lines for table borders?
I wondered about that, but I don't know if it's possible. Any CSS pros out there that might know better?

Dan

dank
06-29-2002, 01:33 AM
Looks like this was in the wrong forum after all...

A quick search turned up that it is indeed possible with CSS.

<style type=text/css>
.dashed { border-width: thin; border-style: dashed; border-color: #000000; padding: 10px; }
</style>

<table class="dashed" ...>
...
</table>

Works fairly nicely, and a bit easier than the other ideas I was toying with. :) It doesn't give a ton of control over line styles, but it's more than sufficient for my purposes.

Dan

Matt
06-29-2002, 03:15 PM
Happy to hear you got it working. -Matt