CMS  Version 3.9
ChromePDFConvertor Class Reference
+ Inheritance diagram for ChromePDFConvertor:
+ Collaboration diagram for ChromePDFConvertor:

Public Member Functions

 __construct ($pdf)
 
 coverPage ($url)
 Provides a separate URL to use as the cover page of the PDF. More...
 
 footer ($text, $position="center", $size=11)
 
 generate ()
 
 screenshot ()
 
 preProcessTemplate ($template)
 
- Public Member Functions inherited from PDFConvertor
 preprocessTemplate ($template)
 

Detailed Description

Definition at line 105 of file pdf.inc.

Constructor & Destructor Documentation

◆ __construct()

ChromePDFConvertor::__construct (   $pdf)

Definition at line 110 of file pdf.inc.

111  {
112  $this->pdf = $pdf;
113  }

Member Function Documentation

◆ coverPage()

ChromePDFConvertor::coverPage (   $url)

Provides a separate URL to use as the cover page of the PDF.

Parameters
string$urlthe URL used to generate the cover page
Returns
PDF

Implements PDFConvertor.

Definition at line 120 of file pdf.inc.

121  {
122  $this->cover = $url;
123  return $this;
124  }
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58

◆ footer()

ChromePDFConvertor::footer (   $text,
  $position = "center",
  $size = 11 
)
Parameters
$text- text of the footer
$position- valid positions are left, right, and center
$size- font size for the footer ?? doesn't work

Implements PDFConvertor.

Definition at line 132 of file pdf.inc.

133  {
134  $this->footer = "--footer-font-size {$size} --footer-{$position} \"{$text}\"";
135  }
footer($text, $position="center", $size=11)
Definition: pdf.inc:132

◆ generate()

ChromePDFConvertor::generate ( )

Implements PDFConvertor.

Definition at line 137 of file pdf.inc.

138  {
139  global $config;
140 
141  $exe = Settings::getValue("pdf", "chrome_path");
142 
143  if (!$exe) throw new FakoliException("Convertor path not specified");
144 
145  $uri = $this->pdf->uri;
146  $uri = appendToQueryString($uri, "__pdfoutput=1");
147  if ($this->pdf->landscape)
148  {
149  $uri = appendToQueryString($uri, "__pdflayout=landscape");
150  }
151 
152  if ($this->pdf->useToken)
153  {
155  $uri = "/action/auto_login/authenticate?token=$token";
156  }
157 
158  $url = "http".($this->pdf->ssl?"s":"")."://".$config["http_host"].$uri;
159 
160  $flags = "--headless --disable-gpu --no-margins --virtual-time-budget=2000";
161 
162  $tmpName = sha1($url . now()) . ".pdf";
163 
164  $output = $this->pdf->output ? $this->pdf->output : (PdfManager::getTempDirectory() . DIRECTORY_SEPARATOR . $tmpName);
165  $cmd = "{$exe} {$flags} \"{$url}\" --print-to-pdf={$output}";
166 
167  trace($cmd, 3);
168 
169  $out = array();
170 
171  exec($cmd, $out);
172 
173  trace(implode("\n", $out), 3);
174 
175  $content = file_get_contents($output);
176  if (!$this->pdf->output) unlink($output);
177 
178  return $content;
179  }
$out
Definition: page.inc:66
static createOneTimeToken($url, $ip_addr=null)
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static getTempDirectory()
Definition: pdf_manager.inc:32
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$output
Definition: generate.inc:9
global $config
Definition: import.inc:4
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24
$uri
Definition: tearoff.inc:4

◆ preProcessTemplate()

ChromePDFConvertor::preProcessTemplate (   $template)

Definition at line 225 of file pdf.inc.

226  {
227  if (!isset($_GET["__pdfoutput"])) return $template;
228  $layout = ($_GET["__pdflayout"] == "landscape") ? " @page { size: landscape; }" : "";
229  $styles = "<style type='text/css' media='print'>{$layout} @page {margin:0;} body { margin: 1.5cm }</style></head>";
230 
231  $template = preg_replace("/<\\/head>/i", $styles, $template);
232  return $template;
233  }
$styles

◆ screenshot()

ChromePDFConvertor::screenshot ( )

Implements PDFConvertor.

Definition at line 181 of file pdf.inc.

182  {
183  global $config;
184 
185  $exe = Settings::getValue("pdf", "chrome_screenshot_path");
186 
187  if (!$exe) throw new FakoliException("Convertor path not specified");
188 
189  $uri = $this->pdf->uri;
190  $uri = appendToQueryString($uri, "__pdfoutput=1");
191  if ($this->pdf->landscape)
192  {
193  $uri = appendToQueryString($uri, "__pdflayout=landscape");
194  }
195 
196  if ($this->pdf->useToken)
197  {
199  $uri = "/action/auto_login/authenticate?token=$token";
200  }
201 
202  $url = "http".($this->pdf->ssl?"s":"")."://".$config["http_host"].$uri;
203 
204  $flags = "";
205 
206  $tmpName = sha1($url . now()) . ".png";
207 
208  $output = $this->pdf->output ? $this->pdf->output : (PdfManager::getTempDirectory() . DIRECTORY_SEPARATOR . $tmpName);
209  $cmd = "{$exe} {$flags} \"{$url}\" {$output}";
210 
211  trace($cmd, 3);
212 
213  $out = array();
214 
215  exec($cmd, $out);
216 
217  trace(implode("\n", $out), 3);
218 
219  $content = file_get_contents($output);
220  if (!$this->pdf->output) unlink($output);
221 
222  return $content;
223  }

The documentation for this class was generated from the following file: