You are here

protected function WkhtmltopdfController::generateFilename in wkhtmltopdf 2.0.x

Generates a filename based on the url

Parameters

string $url: The absolute url that we're generating a pdf of

Return value

string a generated filename that's no longer than 255 chars containing only alphanumeric characters

1 call to WkhtmltopdfController::generateFilename()
WkhtmltopdfController::generatePdf in src/Controller/WkhtmltopdfController.php
Generate pdf file.

File

src/Controller/WkhtmltopdfController.php, line 250

Class

WkhtmltopdfController
A Controller to generate PDFs and return them as a binary reponse.

Namespace

Drupal\wkhtmltopdf\Controller

Code

protected function generateFilename($url) {
  $filename = trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $url), '_') . '.pdf';

  // filenames shouldn't be longer than 255 chars
  if (strlen($filename) > 255) {

    // take from the back to preserve extension
    // URLs tend to have their most important info at the end
    $filename = substr($filename, -255, 255);
  }
  return $filename;
}