works now ! was: bypass shell - pipe into child pid and receive otput



Sherm Pendley wrote:
xhoster@xxxxxxxxx writes:
Mirco Wahab <wahab-mail@xxxxxx> wrote:

print $chld_in $ht;
close $chld_in;
my $pdf; do { local $/; $pdf = <$chld_out> };
You may have a buffering/deadlock problem here, assuming $prog starts
producing output before it completely reads its input.

I'm not certain that's a valid assumption in this case. The job of this
program is to take HTML input and produce PDF output. I don't think it
could do that without first reading all of its input. One can, for example,
include an inline style attribute on the very last p element in the HTML
body, that positions it at the top of the rendered page.

Thank you all for your valuable help. I stripped down the program
to the problem and solved it somehow with the help and input from
this group.

1) the program used is the 'open source' htmldoc 1.9
(http://www.htmldoc.org/software.php)
2) it works(!) as intended (IPC::open2, no shell) via '-'
in old fashioned 'cgi-Mode' but *NOT* under mod-perl!
(I didn't consider this one)

The following is now a perfectly working program:
<cat /cgi-bin/convert.pl>

#!/usr/bin/perl
use strict;
use warnings;
use IPC::Open2;

my $html = q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head><body><h1>PDF it is!</h1>
<p style="height:400px;width:400px;border:blue 1px solid;overflow:hidden;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam sodales, mauris
et consequat condimentum, nisi enim rhoncus nulla, a vulputate arcu ligula non
tortor. Praesent sem. </p></body></html>
};

print "Content-type: application/pdf\n\n"; # print "Content-type: text/html\n\n";
select(STDOUT); $| = 1; # don't buffer
$ENV{HTMLDOC_NOCGI} = 1; # used _as_a_program_ *from* a cgi

my $prog = '/usr/bin/htmldoc';
my @args = qw'--webpage --quiet -t pdf14 -';

my ($chld_out, $chld_in, $childpid);
$childpid = open2($chld_out, $chld_in, $prog, @args)
or die "can't open pipe to $prog: $!";
print $chld_in $html;
close $chld_in;
my $pdf; do { local $/; $pdf = <$chld_out> };
close $chld_out;
waitpid $childpid, 0;
print $pdf;

</>

In my trials before - it bailed because of the mod_perl
environment (I guess), something the program didn't like
(don't really know what).

In the end, the program is a nice solution for
on-the-fly generation of pdf.

Thanks to all people involved (Anno, Ilya, Uri, Xho)

Regards

Mirco
.



Relevant Pages

  • Re: Jargons of Info Tech industry
    ... What an HTML interpreter does by _design_ is not in the same category ... I'm talking about what HTML is designed to do, which is to describe a presentation ... IMO pdf comes close. ...
    (comp.unix.programmer)
  • Re: Editors
    ... >> and simply split up the big HTML version Randy's already got? ... in something easier to browse than PDF files...to the point that both ... which about a decade ago now - Microsoft switched to these CHM files, ... RTF files don't come into this and would prove more horrible than what ...
    (alt.lang.asm)
  • Re: A prediction about the Presidential campaign
    ... easily done in straight HTML. ... There aren't any fonts that automatically use that ligature whenever ... I'm not a font designer. ... Easy in PDF: I just tell my graphing program to spit out ...
    (rec.arts.sf.fandom)
  • Re: Please Help! (Mail merge e-mailing with images in Body)
    ... Well the PDF way does not sound like what I want to do, ... I'll likely just go back to sending e-mails without images ... > an html merge with graphics to e-mail worked as you intended. ... > Word MVP web site http://word.mvps.org ...
    (microsoft.public.word.mailmerge.fields)
  • Re: reinventing the pdf wheel
    ... Yeah - tha's why I suggested using word to print HTML documents. ... about pdf generation, your suggestion has probably already been found less ... WTF would you make such a suggestion. ...
    (comp.lang.php)