diff --git a/print_pdf/print_pdf.admin.inc b/print_pdf/print_pdf.admin.inc
index 2a7462857fd68a043b7556d920c57b02dd1a0662..ae3813721c7805a79306c45dd361fffac7084c21 100644
--- a/print_pdf/print_pdf.admin.inc
+++ b/print_pdf/print_pdf.admin.inc
@@ -168,6 +168,31 @@ function print_pdf_settings() {
'#maxlength' => 3,
'#description' => t('(TCPDF only) Set the font size to be used for normal text. This is the base value for the scaling applied to other text styles.'),
);
+ if (module_exists('token')) {
+ $form['settings']['print_pdf_filename'] = array(
+ '#type' => 'textfield',
+ '#title' => t('PDF File Name'),
+ '#default_value' => variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT),
+ '#description' => t("If left empty the generated filename defaults to the node's path. Tokens may be used to build the filename (see following list). The .pdf extension will be appended automatically."),
+ );
+ $form['settings']['print_pdf_filename_patterns'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Replacement Patterns'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $descriptions = '';
+ $tokens = token_get_list('node');
+ foreach ($tokens as $token) {
+ foreach ($token as $key => $val) {
+ $descriptions .= '
['. $key .']'. $val ."\n";
+ }
+ }
+ $form['settings']['print_pdf_filename_patterns']['descriptions'] = array(
+ '#type' => 'markup',
+ '#value' => "\n". $descriptions ."
\n",
+ );
+ }
$form['#validate']['_print_pdf_settings_validate'] = array();
}
else {
diff --git a/print_pdf/print_pdf.install b/print_pdf/print_pdf.install
index 5ea38254d10cb0a43eee37b736b7d767ec7458d3..f71dd785fb893f8efb20bbaac48591401dbf5ed6 100644
--- a/print_pdf/print_pdf.install
+++ b/print_pdf/print_pdf.install
@@ -69,6 +69,7 @@ function print_pdf_uninstall() {
variable_del('print_pdf_font_size');
variable_del('print_pdf_link_text');
variable_del('print_pdf_link_use_alias');
+ variable_del('print_pdf_filename');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_pdf\_display\_%'");
while ($variable = db_fetch_object($settings)) {
variable_del($variable->name);
diff --git a/print_pdf/print_pdf.module b/print_pdf/print_pdf.module
index e31e1ba58543e760467451cfb0168ec96ea46046..f187b2efa187e68c6c2fefd8c1517edb68ac1c48 100644
--- a/print_pdf/print_pdf.module
+++ b/print_pdf/print_pdf.module
@@ -28,6 +28,7 @@ define('PRINT_PDF_PAPER_SIZE_DEFAULT', 'A4');
define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
define('PRINT_PDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_FONT_SIZE_DEFAULT', 10);
+define('PRINT_PDF_FILENAME_DEFAULT', '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]');
/**
* Implementation of hook_init().
diff --git a/print_pdf/print_pdf.pages.inc b/print_pdf/print_pdf.pages.inc
index 339bc95ce2de481c5916ad93a3b12624ecce9f3b..d1e4655d2b042efad250e5938983e081df36911e 100644
--- a/print_pdf/print_pdf.pages.inc
+++ b/print_pdf/print_pdf.pages.inc
@@ -55,11 +55,18 @@ function print_pdf_controller() {
$html = ob_get_contents();
ob_end_clean();
+ $pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
+ if (function_exists('token_replace') && !empty($pdf_filename)) {
+ $pdf_filename = token_replace($pdf_filename, 'node', $node) .'.pdf';
+ }
+ else {
+ $pdf_filename = str_replace('/', '_', $path) .'.pdf';
+ }
if (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
- _print_pdf_dompdf($print, $html, $path .'.pdf');
+ _print_pdf_dompdf($print, $html, $pdf_filename);
}
elseif (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
- _print_pdf_tcpdf($print, $html, $path .'.pdf');
+ _print_pdf_tcpdf($print, $html, $pdf_filename);
}
else {
return drupal_not_found();