Development

#2304: sfDomPDFPlugin.diff

You must first sign up to be able to contribute.

Ticket #2304: sfDomPDFPlugin.diff

File sfDomPDFPlugin.diff, 8.0 kB (added by temsse79, 1 year ago)
  • lib/sfDomPDFPlugin.class.php

    old new  
    1111   * 
    1212   * @var string 
    1313   */ 
    14   private $config_file = 'lib/dompdf/dompdf_config.inc.php'; 
    15    
     14  private $config_file = 'dompdf/dompdf_config.inc.php'; 
     15 
    1616  /** 
    1717   * The variable that will hold our dompdf object 
    1818   * 
    1919   * @var object 
    2020   */ 
    2121  private $dompdf = null; 
    22        
     22 
    2323  /** 
    24    * Instantiates our domPDF class.   
     24   * Instantiates our domPDF class. 
    2525   * This constructor will check for the presence of domPDF 
    2626   * You can optionally pass your HTML to this constructor 
    2727   * 
     
    3333    if (!file_exists($this->getConfigFile())) 
    3434    { 
    3535      throw new sfException('The domPDF configuration file could not be found in ' . $this->getConfigFile()); 
    36     }   
    37      
     36    } 
     37 
    3838    // Include the configuration file 
    3939    require_once ($this->getConfigFile()); 
    40      
     40 
    4141    // Instantiate the new DOMPDF class 
    4242    $this->setPDF(new DOMPDF()); 
    43      
     43 
    4444    // If input is passed in the constructor, set it here 
    4545    if (!empty($input)) $this->setInput($input); 
    46      
     46 
    4747    // Set the initial paper settings 
    4848    $this->setPaper(); 
    4949  } 
     
    5757  { 
    5858    $this->config_file = $config_file; 
    5959  } 
    60    
     60 
    6161  /** 
    6262   * Check to see if this system is running a Windows platform 
    6363   * 
     
    6565   */ 
    6666  public function isWindows() 
    6767  { 
    68    return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false; 
     68    return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false; 
    6969  } 
    70    
     70 
    7171  /** 
    7272   * Gets the absolute path to the configuration file 
    7373   * 
    7474   * @return string 
    75    */   
     75   */ 
    7676  public function getConfigFile() 
    7777  { 
    78    $isWin = $this->isWindows(); 
    79      
     78    $isWin = $this->isWindows(); 
     79 
    8080    if ((!$isWin && substr($this->config_file, 0, 1) !== '/') || ($isWin && substr($this->config_file, 1, 1) !== ':')) 
    8181    { 
    8282      $this->setConfigFile(realpath(dirname(__FILE__)) . '/' . $this->config_file); 
    8383    } 
    84      
     84 
    8585    return $this->config_file; 
    86   }     
    87      
     86  } 
     87 
    8888  /** 
    8989   * Sets the dompdf object 
    9090   * 
     
    9494  { 
    9595    $this->dompdf = $object; 
    9696  } 
    97    
     97 
    9898  /** 
    9999   * Returns the domPDF object 
    100100   * 
     
    104104  { 
    105105    return $this->dompdf; 
    106106  } 
    107    
     107 
    108108  /** 
    109109   * The HTML input that will be converted to PDF 
    110110   * You can optionally include an actual file instead of a string 
     
    118118    { 
    119119      $this->getPDF()->load_html($input); 
    120120    } 
    121     else  
     121    else 
    122122    { 
    123123      $this->getPDF()->load_html_file($input); 
    124124    } 
    125125  } 
    126    
     126 
    127127  /** 
    128128   * Define either http:// or https:// to access your host 
    129129   * 
     
    133133  { 
    134134    $this->getPDF()->set_protocol($protocol); 
    135135  } 
    136    
     136 
    137137  /** 
    138138   * The URL to the site which hosts your CSS and images 
    139139   * Do not include http:// or https:// 
     
    144144  { 
    145145    $this->getPDF()->set_host($host); 
    146146  } 
    147    
     147 
    148148  /** 
    149149   * Sets the base path for which to look for CSS files and images 
    150150   * 
     
    165165  { 
    166166    $this->getPDF()->set_paper($paper, $orientation); 
    167167  } 
    168      
     168 
    169169  /** 
    170170   * Converts the HTML string into a PDF 
    171171   * 
     
    175175  { 
    176176    return $this->getPDF()->render(); 
    177177  } 
    178    
     178 
    179179  /** 
    180180   * Generates the PDF file based on our input 
    181181   * 
     
    183183   */ 
    184184  public function execute() 
    185185  { 
    186     // Render the output to PDF     
     186    // Render the output to PDF 
    187187    $this->render(); 
    188      
     188 
    189189    return $this->getPDF()->output(); 
    190190  } 
    191191} 
  • sfDomPDFPlugin.class.php

    old new  
    1 <?php 
    2 /** 
    3  * The sfDomPDFPlugin uses the domPDF library to convert HTML documents to PDF 
    4  * Documentation is located at http://trac.symfony-project.com/trac/wiki/sfDomPDFPlugin 
    5  * 
    6  */ 
    7 class sfDomPDFPlugin 
    8 { 
    9   /** 
    10    * The relative path to the dompdf configuration file 
    11    * 
    12    * @var string 
    13    */ 
    14   private $config_file = 'lib/dompdf/dompdf_config.inc.php'; 
    15    
    16   /** 
    17    * The variable that will hold our dompdf object 
    18    * 
    19    * @var object 
    20    */ 
    21   private $dompdf = null; 
    22        
    23   /** 
    24    * Instantiates our domPDF class.   
    25    * This constructor will check for the presence of domPDF 
    26    * You can optionally pass your HTML to this constructor 
    27    * 
    28    * @param string $input 
    29    */ 
    30   public function __construct($input = null) 
    31   { 
    32     // If the configuration cannot be found, throw an error 
    33     if (!file_exists($this->getConfigFile())) 
    34     { 
    35       throw new sfException('The domPDF configuration file could not be found in ' . $this->getConfigFile()); 
    36     }   
    37      
    38     // Include the configuration file 
    39     require_once ($this->getConfigFile()); 
    40      
    41     // Instantiate the new DOMPDF class 
    42     $this->setPDF(new DOMPDF()); 
    43      
    44     // If input is passed in the constructor, set it here 
    45     if (!empty($input)) $this->setInput($input); 
    46      
    47     // Set the initial paper settings 
    48     $this->setPaper(); 
    49   } 
    50  
    51   /** 
    52    * Set the path to the domPDF configuration file 
    53    * 
    54    * @param string $config_file 
    55    */ 
    56   public function setConfigFile($config_file) 
    57   { 
    58     $this->config_file = $config_file; 
    59   } 
    60    
    61   /** 
    62    * Check to see if this system is running a Windows platform 
    63    * 
    64    * @return bool 
    65    */ 
    66   public function isWindows() 
    67   { 
    68     return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false; 
    69   } 
    70    
    71   /** 
    72    * Gets the absolute path to the configuration file 
    73    * 
    74    * @return string 
    75    */   
    76   public function getConfigFile() 
    77   { 
    78     $isWin = $this->isWindows(); 
    79      
    80     if ((!$isWin && substr($this->config_file, 0, 1) !== '/') || ($isWin && substr($this->config_file, 1, 1) !== ':')) 
    81     { 
    82       $this->setConfigFile(realpath(dirname(__FILE__)) . '/' . $this->config_file); 
    83     } 
    84      
    85     return $this->config_file; 
    86   }      
    87      
    88   /** 
    89    * Sets the dompdf object 
    90    * 
    91    * @param object $object 
    92    */ 
    93   public function setPDF($object) 
    94   { 
    95     $this->dompdf = $object; 
    96   } 
    97    
    98   /** 
    99    * Returns the domPDF object 
    100    * 
    101    * @return object 
    102    */ 
    103   public function getPDF() 
    104   { 
    105     return $this->dompdf; 
    106   } 
    107    
    108   /** 
    109    * The HTML input that will be converted to PDF 
    110    * You can optionally include an actual file instead of a string 
    111    * 
    112    * @param string $input 
    113    * @param boolean $is_string 
    114    */ 
    115   public function setInput($input, $is_string = true) 
    116   { 
    117     if ( (bool) $is_string === true) 
    118     { 
    119       $this->getPDF()->load_html($input); 
    120     } 
    121     else  
    122     { 
    123       $this->getPDF()->load_html_file($input); 
    124     } 
    125   } 
    126    
    127   /** 
    128    * Define either http:// or https:// to access your host 
    129    * 
    130    * @param string $protocol 
    131    */ 
    132   public function setProtocol($protocol) 
    133   { 
    134     $this->getPDF()->set_protocol($protocol); 
    135   } 
    136    
    137   /** 
    138    * The URL to the site which hosts your CSS and images 
    139    * Do not include http:// or https:// 
    140    * 
    141    * @param string $host 
    142    */ 
    143   public function setHost($host) 
    144   { 
    145     $this->getPDF()->set_host($host); 
    146   } 
    147    
    148   /** 
    149    * Sets the base path for which to look for CSS files and images 
    150    * 
    151    * @param string $base_path 
    152    */ 
    153   public function setBasePath($base_path) 
    154   { 
    155     $this->getPDF()->set_base_path($base_path); 
    156   } 
    157  
    158   /** 
    159    * Define the type of paper and orientation for domPDF to use 
    160    * 
    161    * @param string $paper 
    162    * @param string $orientation 
    163    */ 
    164   public function setPaper($paper = 'letter', $orientation = 'portrait') 
    165   { 
    166     $this->getPDF()->set_paper($paper, $orientation); 
    167   } 
    168      
    169   /** 
    170    * Converts the HTML string into a PDF 
    171    * 
    172    * @return binary 
    173    */ 
    174   public function render() 
    175   { 
    176     return $this->getPDF()->render(); 
    177   } 
    178    
    179   /** 
    180    * Generates the PDF file based on our input 
    181    * 
    182    * @return binary 
    183    */ 
    184   public function execute() 
    185   { 
    186     // Render the output to PDF     
    187     $this->render(); 
    188      
    189     return $this->getPDF()->output(); 
    190   } 
    191 }