Ver Mensaje Individual
  #4 (permalink)  
Antiguo 29/03/2007, 20:25
eltraful
 
Fecha de Ingreso: marzo-2007
Mensajes: 2
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: Imprimir archivo pdf directamente

Si se puede imprimir directamente desde php un pdf sin pasar por el view
como? Aca paso dos codigos PHP de ejemplo

index.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

<script>
var a

function imprime() {
a=document.frames['iframeOculto'].location='ex.php'
}

</script>

</head>

<body>

<input name="" type="button" onclick="imprime()" value="Print" />

<iframe id="iframeOculto" name="iframeOcultoDX" style="width:0px; height:0px; border:0px"></iframe>
</body>
</html>

ex.php
<?php
define('FPDF_FONTPATH','font/');
require('fpdf_js.php');

class PDF_AutoPrint extends PDF_Javascript
{
function AutoPrint($dialog=false)
{
//Launch the print dialog or start printing immediately on the standard printer
$param=($dialog ? 'true' : 'false');
$script="print($param);";
$this->IncludeJS($script);
}

function AutoPrintToPrinter($server, $printer, $dialog=false)
{
//Print on a shared printer (requires at least Acrobat 6)
$script = "var pp = getPrintParams();";
if($dialog)
$script .= "pp.interactive = pp.constants.interactionLevel.full;";
else
$script .= "pp.interactive = pp.constants.interactionLevel.automatic;";
$script .= "pp.printerName = '\\\\\\\\".$server."\\\\".$printer."';";
$script .= "print(pp);";
$this->IncludeJS($script);
}
}

$pdf=new PDF_AutoPrint();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->Text(90, 50, 'Print PDF! en frame oculto');
//Launch the print dialog
$pdf->AutoPrint(false);
$pdf->Output(); ?>

Ademas hay que incluir los siguientes archivos
fpdf.php
fpdf_js.php

mas el directorio font Estas dos ultimos php mas los font lo bajas de
www punto fpdf punto org

La idea es mandar el pdf a un iframe oculto, asi que lo muestra lo manda a imrpimir a la imrpesora por default pero no se ve.
Funciona de maravillas!!!!!!!!!!!!!.

Última edición por eltraful; 29/03/2007 a las 20:43