PerlGuruWannabee has asked for the wisdom of the Perl Monks concerning the following question:

I need help in finding a solution to the following problem I have a PERL driven website that gathers information and eventually using cascading websheet format tries to print the data on an IRS form image. Works great if the user removes printing headers and footers and sets margins to 0.25" all around. Currently on loading that page I have a warning alert that pops up to make that declaration. But whereas, "Johnny Can`t Read" or perhaps "Johnny Won`t Read", it is being ignored. They print it out and it is malaligned. Again they don`t look at it and send me garbage I cannot use. What I understand is that the printing function cannot be controlled by the website. (I hope not true) But if it is, perhaps I can detect whether the margins and header/footer has been corrected and keep flagging that it needs to be changed by the user until it is. Can anyone give me some code to do one or the other, please dale@sacbiz.com

Replies are listed 'Best First'.
Re: Browser Print Margin Control
by $name (Pilgrim) on Feb 04, 2002 at 20:41 UTC
    I've used PDF::Create with some success for company envelopes and time sheets that are backended by pgsql database that way all your docs stay formatted the way you ant them
    $name
Re: Browser Print Margin Control
by Biker (Priest) on Feb 04, 2002 at 22:09 UTC

    You're not supposed to be able to change settings in your visitors computer. Working as designed. Of course, I could write a Web browser that would let you. But noone would (hopefully) use my browser if so designed.

    Why?
    OK, so you're a nice guy. You wouldn't try to change any settings in my computer unless I explicitly agree to it while visiting your site. Fine. But the next site I visit might have an evil Webmaster. Changing all sorts of settings in my computer, without asking me first. OK, so I could clean up and decide to never visit the evil site again.

    Now, imagine that it's my Mother visiting that evil guys site. She'd never be able to reset things as they were. She'd have to bring her PC to the shop "to get it repaired".

    I hope you get the point. You're nice, but not everyone is as kind as you are.

    "Livet är hårt" sa bonden.
    "Grymt" sa grisen...

Use PostScript - Re: Browser Print Margin Control
by metadoktor (Hermit) on Feb 05, 2002 at 01:35 UTC
    If they are sending you the form then why do you need them to print it and send it back to you?

    Why don't you take the data and superimpose it on the IRS form on your server and then you can have absolute control on how it prints.

    If you want to control how a document prints you will likely need to learn Adobe's PostScript language which is a language for controlling how documents print. There are commands in PostScript that allow you to set the margin to whatever you like.

    metadoktor

    "The doktor is in."

      And PostScript is fun, in a twisted kind of way. Stack based languages are neat.
      You have complete control over every aspect of document rendering with PostScript, margins are just the tip of the iceberg.
      I used to use it to print up my own made up magic cards. (Of course nowadays, I'd probably script it in perl with the gimp or GD).

      -pete
      Entropy is not what is used to be.
Re: Browser Print Margin Control
by toma (Vicar) on Feb 05, 2002 at 05:11 UTC
    PDF is better than HTML for controlling printouts.

    There was a PDF question about fillout-forms a while back called Dynamic Forms. The approach I outlined is still reasonable, although there has been progress since then in the perl modules that work directly with PDF files.

    The IRS forms don't need to be dumb images, they are actually reasonable PDF files that you can work with.

    It should work perfectly the first time! - toma

Re: Browser Print Margin Control
by wmono (Friar) on Feb 04, 2002 at 20:35 UTC

    Unless there's a browser that executes Perl from a HTML file that I just haven't heard about, this really doesn't look like a Perl question.

    You might have better luck if you try coding this in JavaScript. I have no idea whether JavaScript can check or change a browser's printer settings, but at least the probability of that is higher than trying to do it at the server.

Re: Browser Print Margin Control
by mattr (Curate) on Feb 05, 2002 at 14:53 UTC
    Compositing it on your server sounds like the best bet, and it could be done as-is, in pdf, or using image compositing software.

    Or, if you've eaten a bowl of hot peppers and feel antsy, you could write a Perl client application which does this on their computer. Hard to tweak though. Been looking at Ch. 5 of Windows NT Win32 Perl Programming: The Standard Extensions by Dave Roth. (My New Years present to myself).

    Looks like M$ published an OLE reference to Office 97 which conceivably could help you find out how their printer is set up. Likewise you could write an ActiveX in Perl that does this task. Same book tells all (well, much) Nothing in it about printers per se, though there is stuff about accessing shares. I think this is frontier stuff cowboy..

    Well, I just googled with keywords OLE printer margin. Hmm, first hit gives me "XL.ActiveSheet.PageSetup.LeftMargin = 18"! Run that through the mixer! Add the keyword "automation" and there's a lot more links to go through.

    Finally I found something called "HOWTO: Use a VB ActiveX Component for Word Automation From Internet Explorer (Q286023)". Huh. M$ says it is a good way to get load off the server. Anyway, seems like this could be done in Perl too.

    Of course this is totally useless if your customers are on Linux which is happening a bit more rapidly these days. Server side maybe is the safest since you don't have to wrestle with possibly badly documented object models etc.

Re: Browser Print Margin Control
by beebware (Pilgrim) on Feb 06, 2002 at 14:23 UTC

    Have you tried generating a PDF using PDFLib.com or just generating a HTML file and then pushing it through a PS/PDF convertor such as HTML2PS? Don't forget you could use CSS to set the media layout for each page when displaying it.

    The really difficult bit is making sure that not only has the user removed any specific print margins, footers and hearders, but that the paper is aligned in the printer correctly and the right way round... Sometimes it is easier to ignore the pre-printed paper and print the entire form from scratch to your (tweaked) specifications.