Search code examples
javascriptphphtmlformsdompdf

Change size to PDF page (DOMPDF)


I'm creating a huge form, and I'm using a bank credit template as a basis. There's a slight issue: When DOMPDF exports the content, it won't fit in the page. How can I change the page size? I tried with $dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait'); and

$customPaper = array(0,0,360,360);
$dompdf->set_paper($customPaper);

but it won't work. It displays the following: Please click to see the error displayed

Here's the big ass snippet of my code.

<?php 
    require_once("dompdf/dompdf_config.inc.php");
    session_start();
                    if($_POST){
                        $empresa= $_POST["empresa"];
                        $fechaent= $_POST["fechaent"];
                        $horaent= $_POST["hentrada"];
                        $tecnico= $_POST["tecnico"];
                        $horasal= $_POST["hsalida"];
                        $rvisita= $_POST["razonvisita"];
                        $comentarios= $_POST["comentarios"];
                        $trabajor= $_POST["trabajorealizado"];
                    }
                    $codigoHTML='
                        <html>
                           <head>
                              <link rel=Stylesheet href=stylesheet.css>
                              <style>
                                h1 { font-size:40px; text-align:center; font-weight:bold; margin-bottom:10px; text-shadow:0 0 3px #ddd; }
                                h2 { font-size:15px; text-align:left; font-weight:bold; margin-bottom:10px; }
                                h3 { font-size:20px; text-align:left; font-weight:bold; margin-bottom:10px; text-shadow:0 0 3px #ddd; }
                                pre {background-color:"WHITE"; font-family:Arial; margin-left:50px; margin-right:50px;}
                                b{ font-family:Calibri;
                                }
                                p.demo { background-color:"white"; width:100px; margin:10px 0; font-family:Arial; }
                              </style>
                           </head>
                           <body link="#0563C1" vlink="#954F72" class=xl65 style="width:50%;">
                              <table border=0 cellpadding=0 cellspacing=0 width=auto ">
                                 <tr height=20 >
                                    <td height=20 class=xl65 width=64 style="height:15.0pt;width:48pt"></td>
                                    <td colspan=12 rowspan=3 class=xl67 width=894 style="width:671pt"><font
                                       class="font6">FORMULARIO DE CONOCIMIENTO DEL CLIENTE SECTOR ASEGURADOR<br>
                                       COMISION NACIONAL DE BANCOS Y SEGUROS</font><font class="font5"><br>
                                       (Con base a Resolución N° 1393/26-12-2007 y 184/12-02-2008)</font>
                                    </td>
                                    <td class=xl65 width=64 style="width:48pt"></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=21 >
                                    <td height=21 class=xl65 ></td>
                                 </tr>
                                 <tr height=20 style="height:15.0pt">
                                     <td height=20 class=xl65 style="height:15.0pt"></td>
                                     <td colspan=12 rowspan=2 class=xl138 style="border-right:1.0pt solid black;
                                        border-bottom:.5pt solid black">Tipo de Relación: 
                                       <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0">
                                           Radio</label>
                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_2">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_3">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_4">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_5">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_6">
                                           Radio</label>

                                         <label>
                                           <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_7">
                                           Radio</label>

                                    </td>
                                     <td class=xl65></td>
                                  </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl142 style="border-right:1.0pt solid black">I. DATOS
                                       PERSONA NATURAL (Para personas juridicas serán las del Representante)
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=3 class=xl144>Primer Apellido</td>
                                    <td colspan=4 class=xl95 style="border-left:none">Segundo Apellido</td>
                                    <td colspan=5 class=xl95 style="border-right:1.0pt solid black;border-left:
                                       none">Nombres</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=3 class=xl87>&nbsp;</td>
                                    <td colspan=4 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=5 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl146 style="border-right:1.0pt solid black">Tipo de
                                       Identificación
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=2 rowspan=2 class=xl144>Número de Documento</td>
                                    <td colspan=3 rowspan=2 class=xl95>Lugar y Fecha de Expedición</td>
                                    <td colspan=3 rowspan=2 class=xl95>Fecha de Nacimiento</td>
                                    <td colspan=2 rowspan=2 class=xl98 width=148 style="width:111pt">Lugar de
                                       Nacimiento
                                    </td>
                                    <td colspan=2 rowspan=2 class=xl95 style="border-right:1.0pt solid black">Estado
                                       Civil
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=2 rowspan=3 class=xl87>&nbsp;</td>
                                    <td colspan=3 rowspan=3 class=xl79>&nbsp;</td>
                                    <td class=xl95 style="border-top:none;border-left:none">Día</td>
                                    <td class=xl95 style="border-top:none;border-left:none">Mes</td>
                                    <td class=xl95 style="border-top:none;border-left:none">Año</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td rowspan=2 class=xl79 style="border-top:none">&nbsp;</td>
                                    <td rowspan=2 class=xl79 style="border-top:none">&nbsp;</td>
                                    <td rowspan=2 class=xl79 style="border-top:none">&nbsp;</td>
                                    <td colspan=4 class=xl95 style="border-right:1.0pt solid black;border-left:
                                       none">Nombre del Cónyugue</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=4 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=2 class=xl144>Genero</td>
                                    <td colspan=3 rowspan=2 class=xl95>Nacionalidad</td>
                                    <td colspan=7 rowspan=2 class=xl95 style="border-right:1.0pt solid black">Profesión,
                                       Oficio y Ocupación
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl144 style="border-top:none">Masculino</td>
                                    <td class=xl95 style="border-top:none;border-left:none">Femenino</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl87 style="border-top:none">&nbsp;</td>
                                    <td class=xl79 style="border-top:none;border-left:none">&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=7 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl148 style="border-right:1.0pt solid black">Dirección
                                       Residencia
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl87 style="border-right:1.0pt solid black">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl144 style="border-top:none">Municipio</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Departamento</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Pais</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Telefono</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Celular</td>
                                    <td colspan=3 class=xl95 style="border-right:1.0pt solid black;border-left:
                                       none">Correo Electrónico</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td class=xl87 style="border-top:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl150 style="border-right:1.0pt solid black">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=3 class=xl144>Empresa donde trabaja</td>
                                    <td colspan=3 class=xl95 style="border-left:none">Área</td>
                                    <td colspan=3 class=xl95 style="border-left:none">Cargo</td>
                                    <td colspan=3 class=xl94 style="border-right:1.0pt solid black;border-left:
                                       none">Tiempo de Laborar</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=3 class=xl87>&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=20 >
                                    <td height=20 class=xl65 ></td>
                                    <td colspan=12 class=xl144 style="border-right:1.0pt solid black">Dirección
                                       Laboral
                                    </td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=19 >
                                    <td height=19 class=xl65 style="height:14.25pt"></td>
                                    <td colspan=12 class=xl87 style="border-right:1.0pt solid black">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=19 >
                                    <td height=19 class=xl65 style="height:14.25pt"></td>
                                    <td class=xl144 style="border-top:none">Municipio</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Departamento</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Pais</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Telefono</td>
                                    <td colspan=2 class=xl95 style="border-left:none">Fax</td>
                                    <td colspan=3 class=xl95 style="border-right:1.0pt solid black;border-left:
                                       none">Correo Electrónico</td>
                                    <td class=xl65></td>
                                 </tr>
                                 <tr height=19 >
                                    <td height=19 class=xl65 style="height:14.25pt"></td>
                                    <td class=xl87 style="border-top:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=2 class=xl79 style="border-left:none">&nbsp;</td>
                                    <td colspan=3 class=xl79 style="border-right:1.0pt solid black;border-left:
                                       none">&nbsp;</td>
                                    <td class=xl65></td>
                                 </tr>
                                  </table>
                               </body>
                            </html>        
                    ';
        $filename="- formulario.pdf";
        $codigoHTML=utf8_decode($codigoHTML);
        $dompdf=new DOMPDF();
        $dompdf->load_html($codigoHTML);
        ini_set("memory_limit","128M");
        $customPaper = array(0,0,360,360);
        $dompdf->set_paper($customPaper);
        $dompdf->render();
        $pdf=$dompdf->output($filename);
        file_put_contents("forms/".$filename, $pdf);
        $mi_pdf = "forms/".$filename; 
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="'.$mi_pdf.'"');
        readfile($mi_pdf);
?>

Solution

  • Issue was on DOMPDF version.

    To change the page size:

    $customPaper = array(0,0,360,360);
    $dompdf->set_paper($customPaper);