Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:40:48+00:00 2026-06-15T03:40:48+00:00

I have a project to save pages created dynamically with php and store them

  • 0

I have a project to save pages created dynamically with php and store them on the server.

I am planning to store a replica of the page as a pdf; with all their images, tables and the layout.

I tried to use these tools:

  • DOMPDF
  • FPDF

But I honestly do not think it’s going on the right track

Have any solutions or could these tools solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:40:49+00:00Added an answer on June 15, 2026 at 3:40 am

    From forosdelweb

    We are going to create a class to make the convertion in convertToPDF.php

    <?php 
    /*----------------------------------------------------------/* 
    
    $path     : name of the file pdf (without the extension) 
                    i.e.: --> 'ejemplo' , 'pdfs/nuevo-ejemplo' 
                    if empty --> it will be random 
    
    $content  : content of the pdf 
    
    $body     : true or false. 
                    true  --> add; <doctype>, <body>, <head> to $content 
                    false --> do not alter the $content 
    
    $style    : the path of the CSS. It could be empty 
                     To load the css --> needs $body = true; 
    
    $mode     : true or false. 
                    true  --> save the file on the server and then show it  
                    false --> ask where to save it  
    
    $paper_1  : size of the paper[*] 
    $paper_2  : style of the paper[*] 
    
        [*] To see more options:  
            --> http://code.google.com/p/dompdf/wiki/Usage#Invoking_dompdf_via_the_command_line 
    
    /*----------------------------------------------------------*/  
    
    require_once("dompdf/dompdf_config.inc.php"); 
    
    function doPDF($path='',$content='',$body=false,$style='',$mode=false,$paper_1='a4',$paper_2='portrait') 
    {     
        if( $body!=true and $body!=false ) $body=false; 
        if( $mode!=true and $mode!=false ) $mode=false; 
    
        if( $body == true ) 
        { 
            $content=' 
            <!doctype html> 
            <html> 
            <head> 
                <link rel="stylesheet" href="'.$style.'" type="text/css" /> 
            </head> 
            <body>' 
                .$content. 
            '</body> 
            </html>'; 
        } 
    
        if( $content!='' ) 
        {         
            //Añadimos la extensión del archivo. Si está vacío el nombre lo creamos 
            $path!='' ? $path .='.pdf' : $path = crearNombre(10);   
    
            //Las opciones del papel del PDF. Si no existen se asignan las siguientes:[*] 
            if( $paper_1=='' ) $paper_1='a4'; 
            if( $paper_2=='' ) $paper_2='portrait'; 
    
            $dompdf =  new DOMPDF(); 
            $dompdf -> set_paper($paper_1,$paper_2); 
            $dompdf -> load_html(utf8_encode($content)); 
            //ini_set("memory_limit","32M"); //opcional  
            $dompdf -> render(); 
    
            //Creamos el pdf 
            if($mode==false) 
                $dompdf->stream($path); 
    
            //Lo guardamos en un directorio y lo mostramos 
            if($mode==true) 
                if( file_put_contents($path, $dompdf->output()) ) header('Location: '.$path); 
        } 
    } 
    
    function crearNombre($length) 
    { 
        if( ! isset($length) or ! is_numeric($length) ) $length=6; 
    
        $str  = "0123456789abcdefghijklmnopqrstuvwxyz"; 
        $path = ''; 
    
        for($i=1 ; $i<$length ; $i++) 
          $path .= $str{rand(0,strlen($str)-1)}; 
    
        return $path.'_'.date("d-m-Y_H-i-s").'.pdf';     
    } 
    

    The next step is to create a page in this case index.php

    <?php 
    
    include('convertToPDF.php'); 
    
    //$html= --> Aquí pondriamos por ejemplo la consulta 
    $html=' 
    <img src="http://pxd.me/dompdf/www/images/title.gif"/> 
    
    <table> 
        <tr> 
            <th>Nombre</th> 
            <th>Tipo</th> 
            <th>Imagen</th> 
            <th>Comentario</th> 
            <th>Unidades</th> 
            <th>Precio unidad</th>     
        </tr>     
        <tr> 
            <td>pensandoo</td> 
            <td>icono</td> 
            <td><img src="http://static.forosdelweb.com/fdwtheme/images/smilies/scratchchin.gif"/></td> 
            <td>iconito pensativo</td> 
            <td>3</td> 
            <td>10</td> 
        </tr> 
        <tr> 
            <td>fiesta</td> 
            <td>icono 3</td> 
            <td><img src="http://static.forosdelweb.com/fdwtheme/images/smilies/porra.gif"/></td> 
            <td>iconito festejando</td> 
            <td>1</td> 
            <td>24</td> 
        </tr> 
        <tr> 
            <td>silbando</td> 
            <td>icono</td> 
            <td><img src="http://static.forosdelweb.com/fdwtheme/images/smilies/silbar.gif"/></td> 
            <td>bombilla silbando</td> 
            <td>19</td> 
            <td>50</td> 
        </tr> 
        <tr> 
            <td>no no no</td> 
            <td>icono 2</td> 
            <td><img src="http://static.forosdelweb.com/fdwtheme/images/smilies/negar.gif"/></td> 
            <td>negacion</td> 
            <td>5</td> 
            <td>1</td> 
        </tr> 
    </table> 
    ' 
    
    ?> 
    
    <?php 
    
    if ( isset($_POST['PDF_1']) ) 
        doPDF('ejemplo',$html,false); 
    
    if ( isset($_POST['PDF_2']) ) 
        doPDF('ejemplo',$html,true,'style.css'); 
    
    if ( isset($_POST['PDF_3']) ) 
        doPDF('',$html,true,'style.css'); 
    
    if ( isset($_POST['PDF_4']) ) 
        doPDF('ejemplo',$html,true,'style.css',false,'letter','landscape');  
    
    if ( isset($_POST['PDF_5']) ) 
        doPDF('ejemplo',$html,true,'',true); //asignamos los tags <html><head>... pero no tiene css 
    
    if ( isset($_POST['PDF_6']) ) 
        doPDF('',$html,true,'style.css',true); 
    
    if ( isset($_POST['PDF_7']) ) 
        doPDF('pdfs/nuevo-ejemplo',$html,true,'style.css',true); //lo guardamos en la carpeta pdfs     
    ?> 
    
    <!doctype html> 
    <html> 
    
    <head> 
        <link rel="stylesheet" href="style.css" type="text/css" /> 
    </head> 
    
    <table class="header"> 
        <tr> 
            <td><a href="http://www.forosdelweb.com/f18/" target="_blank"><h1>PHP</h1></a></td> 
            <td><a href="http://www.forosdelweb.com/" target="_blank"><h2>FOROSDELWEB</h2></a></td> 
        </tr> 
    </table> 
    
    <table class="menu"> 
        <tr> 
            <td>Ejemplos para: <strong>dompdf</strong></td> 
            <td><a href="http://code.google.com/p/dompdf/wiki/Usage" target="_blank">Documentaci&oacute;n</a></td> 
            <td><a href="http://code.google.com/p/dompdf/source/browse/trunk/dompdf/dompdf_config.custom.inc.php?r=399" target="_blank">Define()</a></td> 
            <td><a href="http://pxd.me/dompdf/www/examples.php#samples" target="_blank">Ejemplos de dompdf</a></td> 
        </tr> 
    </table> 
    
    <body> 
    
    <?php echo $html ?> 
    
    <form  action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> 
    <table> 
      <tr> 
        <td>Mostrar PDF sin CSS</td> 
        <td><input name="PDF_1" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Mostrar PDF con CSS</td> 
        <td><input name="PDF_2" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Mostrar PDF con CSS sin definir el nombre</td> 
        <td><input name="PDF_3" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Mostrar PDF con CSS y cambiando el formato de la hoja</td> 
        <td><input name="PDF_4" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Guardar y abrir PDF sin CSS</td> 
        <td><input name="PDF_5" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Guardar y abrir PDF con CSS sin definir el nombre</td> 
        <td><input name="PDF_6" type="submit" value="CREAR" /></td> 
      </tr> 
      <tr> 
        <td>Guardar en otro directorio y abrir PDF con CSS</td> 
        <td><input name="PDF_7" type="submit" value="CREAR" /></td> 
      </tr>   
    
    </table> 
    
    </form> 
    
    </body> 
    </html> 
    

    Finally you can have the file for your style style.css

    body{
    font:12px Arial, Tahoma, Verdana, Helvetica, sans-serif;
    background-color:#BECEDC;
    color:#000;
    }
    
    a h1{
    font-size:35px; 
    color:#FFF;
    }
    
    h2{
    color:#FC0;
    font-size:15px; 
    }
    
    table{
    width:100%;
    height:auto;
    margin:10px 0 10px 0;
    border-collapse:collapse;
    text-align:center;
    background-color:#365985;
    color:#FFF;
    }
    
    table td,th{
    border:1px solid black;
    }
    
    table th{
    color:#FC0; 
    }
    
    .menu{
    background-color:#69C;
    color:#FFF;
    }
    
    .menu a{
    color:#FFF; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Netbeans . I have created a simple php project. It
I have an project with many Books. Each book has many Pages. I would
Background: I have a project that is not at all large scale (2 ASP.NET
I am working on a MVC project that is supposed to have one page
I have a portfolio application that lists projects and their detail pages. Every project
I've created a default MVC 3 project and created the default edit page for
I created a new project using aspx visual studio 2010. All I am trying
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I have project I want to upgrade to .Net4 and it use BackgroundCopyManager.dll. Anyone
I have project on rails 3 with multiplayer using Faye. The error block in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.