Operating System - Linux
1752770 Members
5090 Online
108789 Solutions
New Discussion юеВ

Re: line wrap or truncate when printing web page produced by perl pgm

 
SOLVED
Go to solution
John Kittel
Trusted Contributor

line wrap or truncate when printing web page produced by perl pgm

I have a simple perl program to produce a web page. The contents of the web page are a listing of a text file. In the perl program I'm just using the backticks to invoke the cat command to list the file contents, and enclosing that within the html tags
 
.

In the browser, long lines display fine, - user can scroll right to view long lines. But if the user prints the page, the long lines get truncated. I need the lines to be wrapped, not truncated, when the page is printed.

Is there a simple way around this? I don't care whether it gets adressed as a browser (IE) setting, a printer page setup change, a different way of generating the web page, etc. Just hoping it can be accomplished with a simple change.
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: line wrap or truncate when printing web page produced by perl pgm

Hi John:

I think you need to "smarten" you code. Instead of invoking the external 'cat', open and read the file into an array. Assuming that you can compress whitespace and/or split lines, use the 'Test::Wrap' module (available in the core distribution) to reduce the margin's extent. If the data is columnar with fixed whitespace widths, you may be forced to reading and reformatting it yourself.

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: line wrap or truncate when printing web page produced by perl pgm


My first step woudl be to isolate the problem into two parts.

part 1) The perl script to generate the HTML.

part 2) a Browser displaying and printing the page.

In between you have the html file.
Study that with vi or some such.
Is it exactly what you want it to be?
If not, fix the perl,
be first make it how you want it to be with an editor and verify it works as intended.

If the html looks alright, as intended, then it is not a perl/hpux question but an html language question. (What does PRE do? Don't you need a

around paragraphs? )

No go get a bunch of wet noodles out of a cupboard and wack yourself on the hands a few times for extremely poor programming style.
It's just not reasonable to fork a process (backtick); activate a program (cat); make it read a file, send it to a pipe to then have perl read it from that pipe when perl can just read the file directly and with much better options for error handling!
It's... it's.. dare I say this... embarrasing to do otherwise

Just use something like:

$file = shift; # or wherever else you get the name from.
if (open (HTML, ">$html") {
print HTML "

\n" # and more ?
if (open( FILE, "<$file")) {
while () {
print HTML $_; # yes you can write this faster
}
} else {
# input file error handling
}
} else {
# html file create error handling
}

Good luck!
Hein.


John Kittel
Trusted Contributor

Re: line wrap or truncate when printing web page produced by perl pgm

Thanks JRF.

I'll see what I can do with Text::Wrap.
John Kittel
Trusted Contributor

Re: line wrap or truncate when printing web page produced by perl pgm

Text::Wrap worked out nicely and was fairly quick and easy.