Prezaados colegas,<br>
<br>
Estou tentando fazer uma conversao de arquivo HTMl para PDF e não estou conseguindo.<br>
<br>
Esse script baixa uma ou mais paginas HTML passadas como parametro e
depois a transforma em PDF mas a conversão nao esta funcionando .<br>
<br>
Alguem poderia me ajudar ????<br>
<br>
<br>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Kate, the KDE Advanced Text Editor">
<pre><b>#!/usr/bin/perl</b><br><br><b>use</b> <span style="color: rgb(0, 0, 128);">IO::Socket</span>;<br><span style="color: rgb(128, 128, 128);"><i>#use PDF::FromHTML;</i></span><br><span style="color: rgb(128, 128, 128);">
<i>#use HTML::Parse;</i></span><br><span style="color: rgb(128, 128, 128);"><i>#use PDF::Template;</i></span><br><span style="color: rgb(128, 128, 128);"><i>#use HTML::Tagset;</i></span><br><span style="color: rgb(128, 128, 128);">
<i>#use PDF::Writer;        </i></span><br><span style="color: rgb(128, 128, 128);"><i>#use HTML::TreeBuilder;</i></span><br><br><br><span style="color: rgb(128, 0, 0);">$count</span> = <span style="color: rgb(0, 0, 255);">0</span>
;<br><span style="color: rgb(128, 0, 0);">$TotalParametros</span> = <span style="color: rgb(0, 0, 255);">0</span>;<br><span style="color: rgb(128, 0, 0);">$Site</span> = <span style="color: rgb(0, 128, 0);"><b>"</b></span>
<span style="color: rgb(221, 0, 0);"><a href="http://www.faqs.org">www.faqs.org</a></span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br><span style="color: rgb(128, 0, 0);">$HomeUsuario</span> = <span style="color: rgb(0, 128, 0);">
<b>"</b></span><span style="color: rgb(221, 0, 0);">/home/vt_integrada_perl</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>; <span style="color: rgb(128, 128, 128);"><i>#diretorio onde vai ser baixado o arquivo HTML
</i></span><br><span style="color: rgb(128, 0, 0);">$NovoDir</span>;<br><span style="color: rgb(0, 0, 128);">mkdir</span> <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">/home/vt_integrada_perl
</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>; <span style="color: rgb(128, 128, 128);"><i>#cria diretorio home/vt_integrada_perl onde vai ser baixado as paginas HTML</i></span><br><b>foreach</b> <span style="color: rgb(128, 0, 0);">
$arg</span>(<span style="color: rgb(192, 0, 0);">@ARGV</span>) {<br> <span style="color: rgb(128, 0, 0);">$count</span>++;<br>}<br><b>if</b>(<span style="color: rgb(128, 0, 0);">$count</span>==<span style="color: rgb(0, 0, 255);">
0</span>){<br> <span style="color: rgb(0, 0, 128);">printf</span>(<span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">Digite o nome do script e o numero das RFC separadas por espaco
</span><span style="color: rgb(255, 0, 255);">\n</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>);<br>}<br><b>else</b>{<br> <span style="color: rgb(128, 0, 0);">$TotalParametros</span> = <span style="color: rgb(128, 0, 0);">
$count</span>;<br>}<br><br><b>for</b>(<span style="color: rgb(128, 0, 0);">$count</span>=<span style="color: rgb(0, 0, 255);">0</span>;<span style="color: rgb(128, 0, 0);">$count</span><<span style="color: rgb(128, 0, 0);">
$TotalParametros</span>;<span style="color: rgb(128, 0, 0);">$count</span>++){<br> <span style="color: rgb(128, 0, 0);">$ListaDownloads</span>[<span style="color: rgb(128, 0, 0);">$count</span>] = <span style="color: rgb(0, 128, 0);">
<b>"</b></span><span style="color: rgb(221, 0, 0);">/rfcs/rfc</span><span style="color: rgb(0, 128, 0);"><b>"</b></span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>[<span style="color: rgb(128, 0, 0);">$count
</span>] . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">.html</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br> <span style="color: rgb(128, 0, 0);">$NovoDir
</span> = <span style="color: rgb(128, 0, 0);">$HomeUsuario</span> . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">/</span><span style="color: rgb(0, 128, 0);"><b>"</b>
</span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>[<span style="color: rgb(128, 0, 0);">$count</span>];<br> <span style="color: rgb(128, 0, 0);">$NovoArquivo</span> = <span style="color: rgb(128, 0, 0);">$NovoDir
</span> . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">/</span><span style="color: rgb(0, 128, 0);"><b>"</b></span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>
[<span style="color: rgb(128, 0, 0);">$count</span>] . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">.html</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br>
<span style="color: rgb(0, 0, 128);">mkdir</span>(<span style="color: rgb(128, 0, 0);">$NovoDir</span>);<br> &BaixarPagina(<span style="color: rgb(128, 0, 0);">$ListaDownloads</span>[<span style="color: rgb(128, 0, 0);">
$count</span>], <span style="color: rgb(128, 0, 0);">$NovoArquivo</span>);<br> <span style="color: rgb(128, 0, 0);">$ListaDownloads</span>[<span style="color: rgb(128, 0, 0);">$count</span>] = <span style="color: rgb(0, 128, 0);">
<b>"</b></span><span style="color: rgb(221, 0, 0);">/rfcs/rfc</span><span style="color: rgb(0, 128, 0);"><b>"</b></span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>[<span style="color: rgb(128, 0, 0);">$count
</span>] . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">.html</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br> <span style="color: rgb(128, 0, 0);">$NovoDir
</span> = <span style="color: rgb(128, 0, 0);">$HomeUsuario</span> . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">/</span><span style="color: rgb(0, 128, 0);"><b>"</b>
</span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>[<span style="color: rgb(128, 0, 0);">$count</span>];<br> <span style="color: rgb(128, 0, 0);">$NovoArquivo</span> = <span style="color: rgb(128, 0, 0);">$NovoDir
</span> . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">/</span><span style="color: rgb(0, 128, 0);"><b>"</b></span> . <span style="color: rgb(192, 0, 0);">$ARGV</span>
[<span style="color: rgb(128, 0, 0);">$count</span>] . <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">.html</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br>
<span style="color: rgb(128, 128, 128);"><i># &convertePdf;        </i></span><br> <span style="color: rgb(0, 0, 128);">mkdir</span>(<span style="color: rgb(128, 0, 0);">$NovoDir</span>);<br> <br><br><br> <br>}; <br>
<br><b>sub </b><span style="color: rgb(0, 0, 128);">convertePdf</span> {<br><b>my</b> <span style="color: rgb(128, 0, 0);">$HTML</span> = <span style="color: rgb(0, 128, 0);"><b>'</b></span><span style="color: rgb(255, 108, 108);">
caminho_para_o_arquivo_html</span><span style="color: rgb(0, 128, 0);"><b>'</b></span>;<br><b>my</b> <span style="color: rgb(128, 0, 0);">$PDF</span> = <span style="color: rgb(0, 128, 0);"><b>'</b></span><span style="color: rgb(255, 108, 108);">
caminho_para_o_arquivo_pdf</span><span style="color: rgb(0, 128, 0);"><b>'</b></span>;<br><b>my</b> <span style="color: rgb(128, 0, 0);">$FONTE</span> = <span style="color: rgb(0, 128, 0);"><b>'</b></span><span style="color: rgb(255, 108, 108);">
caminho_para_fonte_truetype</span><span style="color: rgb(0, 128, 0);"><b>'</b></span>;<br><br><b>my</b> <span style="color: rgb(128, 0, 0);">$pdf</span> = <span style="color: rgb(0, 0, 128);">PDF::FromHTML</span>->new( encoding =>
<span style="color: rgb(0, 128, 0);"><b>'</b></span><span style="color: rgb(255, 108, 108);">utf-8</span><span style="color: rgb(0, 128, 0);"><b>'</b></span> );<br> <span style="color: rgb(128, 0, 0);">$pdf</span>-><span style="color: rgb(128, 0, 0);">
load_file</span>(<span style="color: rgb(128, 0, 0);">$HTML</span>);<br> <span style="color: rgb(128, 0, 0);">$pdf</span>-><span style="color: rgb(128, 0, 0);">convert</span>(<br> Font => <span style="color: rgb(128, 0, 0);">
$FONTE</span>,<br> LineHeight => <span style="color: rgb(0, 0, 255);">10</span>,<br> Landscape => <span style="color: rgb(0, 0, 255);">1</span>,<br> );<br> <span style="color: rgb(128, 0, 0);">$pdf</span>
-><span style="color: rgb(128, 0, 0);">write_file</span>(<span style="color: rgb(128, 0, 0);">$PDF</span>);<br>}<br><b>sub </b><span style="color: rgb(0, 0, 128);">BaixarPagina</span>{<br> <b>my</b> <span style="color: rgb(128, 0, 0);">
$enderecosite</span> = <span style="color: rgb(192, 0, 0);">$_</span>[<span style="color: rgb(0, 0, 255);">0</span>];<br> <b>my</b> <span style="color: rgb(128, 0, 0);">$nmarquivo</span> = <span style="color: rgb(192, 0, 0);">
$_</span>[<span style="color: rgb(0, 0, 255);">1</span>];<br> <b>my</b> <span style="color: rgb(128, 0, 0);">$port</span> = <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">80
</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br> <b>my</b> <span style="color: rgb(128, 0, 0);">$strComando</span> = <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">
GET </span><span style="color: rgb(128, 0, 0);">$enderecosite</span><span style="color: rgb(221, 0, 0);"> HTTP/1.1</span><span style="color: rgb(255, 0, 255);">\n</span><span style="color: rgb(221, 0, 0);">Host: </span><span style="color: rgb(128, 0, 0);">
$Site</span><span style="color: rgb(255, 0, 255);">\n</span><span style="color: rgb(221, 0, 0);">User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050725</span><span style="color: rgb(255, 0, 255);">\n\n
</span><span style="color: rgb(0, 128, 0);"><b>"</b></span>;<br> <br> <span style="color: rgb(0, 0, 128);">print</span> <span style="color: rgb(128, 0, 0);">$strComando</span>;<br> <b>my</b> <span style="color: rgb(128, 0, 0);">
$sock</span> = new <span style="color: rgb(0, 0, 128);">IO::Socket</span>::<span style="color: rgb(0, 0, 128);">INET</span> (<br> PeerAddr => <span style="color: rgb(128, 0, 0);">$Site
</span>,<br>                                  PeerPort => <span style="color: rgb(128, 0, 0);">$port</span>,<br>                                  Proto => <span style="color: rgb(0, 128, 0);"><b>'</b></span><span style="color: rgb(255, 108, 108);">tcp</span><span style="color: rgb(0, 128, 0);">
<b>'</b></span>,<br>                                 );<br> <span style="color: rgb(0, 0, 128);">die</span> <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">Nao foi possivel conectar... </span><span style="color: rgb(128, 0, 0);">
$Site</span><span style="color: rgb(0, 128, 0);"><b>"</b></span> <b>unless</b> <span style="color: rgb(128, 0, 0);">$sock</span>;<br> <span style="color: rgb(128, 0, 0);">$sock</span>-><span style="color: rgb(128, 0, 0);">
autoflush</span>(<span style="color: rgb(0, 0, 255);">1</span>);<br><br> <span style="color: rgb(0, 0, 128);">print</span> <span style="color: rgb(128, 0, 0);">$sock</span> <span style="color: rgb(128, 0, 0);">$strComando
</span>;<br><br>;<br><br> <b>my</b> <span style="color: rgb(128, 0, 0);">$buf</span>=<span style="color: rgb(0, 128, 0);"><b>""</b></span>;<br> <b>while</b>(<span style="color: rgb(128, 0, 0);">$line</span>=<
<span style="color: rgb(128, 0, 0);">$sock</span>>){<br> <span style="color: rgb(128, 0, 0);">$buf</span>.=<span style="color: rgb(128, 0, 0);">$line</span>;<br> }<br><br>         <br>        <br> <span style="color: rgb(0, 0, 128);">
close</span>(<span style="color: rgb(128, 0, 0);">$sock</span>);<br><br><span style="color: rgb(128, 128, 128);"><i># print $buf; exibe o conteudo html</i></span><br> <span style="color: rgb(0, 0, 128);">open
</span>(SITE,<span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">>></span><span style="color: rgb(128, 0, 0);">$nmarquivo</span><span style="color: rgb(0, 128, 0);"><b>"
</b></span>);<br> <span style="color: rgb(0, 0, 128);">print</span> SITE <span style="color: rgb(128, 0, 0);">$buf</span>;<br> <span style="color: rgb(0, 0, 128);">close</span>(SITE);<br> <span style="color: rgb(0, 0, 128);">
print</span> <span style="color: rgb(0, 128, 0);"><b>"</b></span><span style="color: rgb(221, 0, 0);">Gravado em </span><span style="color: rgb(128, 0, 0);">$nmarquivo</span><span style="color: rgb(0, 128, 0);"><b>"
</b></span>;<br> <br>}</pre> <br>
Outro detalahe tb precisaria converte-lo para TXTe PS mas realemte neste caso estou perdido<br>
<br>
Um abraço <br>
<br>
Carlos Silva<br>