hi there.

i use the following modules:
mimemail-7.x-1.0-alpha2.zip + commerce_billy-7.x-1.0-beta1+5-dev + commerce_billy_mail-7.x-1.x-dev

my problem: the pdf i can download in the browser directly and the pdf that is sent by this module differs very much.
the downloadversion is perfectly stlyed as intended, in the mail version just part styled with css that hard coded in the commerce_order--commerce_order--pdf.tpl.php

i have attached the tpls and two screens.
maybe you have an idea?!

thank you :)

Comments

clay-evans’s picture

StatusFileSize
new320.69 KB
anybody’s picture

Please try the "mailsystem" module and set the correct theme for "Theme to render the emails".

I think the problem is, that different themes are used for rendering!

clay-evans’s picture

I tried this, but didnt help. is used the standard templates for testing that comes with commerce_billy.

how do you have set up your pdf mail?, wich versions you use, this would be interessting because auf this https://drupal.org/comment/8165547#comment-8165547

clay-evans’s picture

when i switch the admin-theme to the current frontend-theme, then the mail.sent pdf is styled as it is streamed. this is very strange.

mailsystem got a theme option and mimemail to. both of them dont change a thing. also i assume they style the MAIL itself and not the pdf. i digging on this a week now. i am the first one who has a closer look to this sent pdf?

clay-evans’s picture

New day new testing.

i currently save the pdf out:

here: commerce_billy_mail.module

function commerce_billy_mail_pdf_create($html, $filename) {
  <strong>$dompdf = commerce_billy_pdf_prepare_dompdf($html, $filename);
  $path = libraries_get_path('dompdf');
    $dir = drupal_realpath('public://');
    define('DOMPDF_FONT_DIR', $dir . '/fonts/');
    define('DOMPDF_TEMP_DIR', file_directory_temp());
    require_once DRUPAL_ROOT . '/' . $path . '/dompdf_config.inc.php';
    spl_autoload_register('DOMPDF_autoload');

    $dompdf = new DOMPDF();
    $dompdf->set_paper('a4', 'portrait');

    $html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'UTF-8'), ENT_NOQUOTES);
    $dompdf->load_html($html);
    $dompdf->render();


	$pdfName = 'test-commerce-billy-pdf.pdf';
	$pdfPath = 'sites/default/files/public/pdf/';
    $html = $dompdf->output();
	// write the pdf content within that file.
    file_put_contents($pdfPath.$pdfName, $html);</strong>

  // write the pdf content within that file.
  $file = file_save_data($htmlData, 'temporary://' . $filename);
  if ($file === FALSE) {
    drupal_set_message('Invoice PDF could not be saved correctly.', 'error');
  }

  // New part end
  return file_stream_wrapper_get_instance_by_uri($file->uri)->realpath();
}

Result: Wrong styling seen in mail.jpg

here: commerce_billy_pdf.module

function commerce_billy_pdf($order) {
  $html = commerce_billy_pdf_html($order);
  $filename = preg_replace('/[^a-z0-9]/', '_', drupal_strtolower('invoice_' . $order->order_number)) . '.pdf';

  try {
    commerce_billy_pdf_output($html, $filename);
	
	<strong>$path = libraries_get_path('dompdf');
    $dir = drupal_realpath('public://');
    define('DOMPDF_FONT_DIR', $dir . '/fonts/');
    define('DOMPDF_TEMP_DIR', file_directory_temp());
    require_once DRUPAL_ROOT . '/' . $path . '/dompdf_config.inc.php';
    spl_autoload_register('DOMPDF_autoload');

    $dompdf = new DOMPDF();
    $dompdf->set_paper('a4', 'portrait');

    $html = htmlspecialchars_decode(htmlentities($html, ENT_NOQUOTES, 'UTF-8'), ENT_NOQUOTES);
    $dompdf->load_html($html);
    $dompdf->render();


	$pdfName = 'test-commerce-billy.pdf';
	$pdfPath = 'sites/default/files/public/pdf/';
    $html = $dompdf->output();
	// write the pdf content within that file.
    file_put_contents($pdfPath.$pdfName, $html);</strong>
	
    drupal_exit();
  }
  catch (DOMPDF_Exception $e) {
    drupal_set_message(t('Error generating PDF invoice. Please contact the website administrator.'), 'error');
    watchdog('commerce_billy_pdf', 'DOMPDF exception while generating pdf invoice: %message', array('%message' => $e->getMessage()), WATCHDOG_ERROR);
    return '';
  }
}

Result: right styling seen in online.jpg

my very big question is, why the hell now they are different?!

as i understand commerce_billy_mail is getting the order-data with this
$html = commerce_billy_pdf_html($order);

clay-evans’s picture

ok got it now.
what i can say is ..dont believe the hype ^^
the mail-sent pdf is styled with the theme that is showing when you are loggend in.
means, as admin your assign theme is the backend-theme, therefor, the pdf is styled with this settings. (for testing purposes i was setting the order-status manually as admin in the backend)

anybody’s picture

Ok should we perhaps exclude the rendering path from the admin theme?

That's possible and so the PDF would always be rendered by the "main" theme. It would then be a task for the commerce_billy module itself.

anybody’s picture

By the way, this would be the hook that does the trick and should go into commerce_billy. I would then mode this issue over there and further discuss it.

function hook_admin_paths_alter(&$paths) {
    $paths['my-path/*'] = FALSE;
}
anybody’s picture

Status: Active » Needs work
anybody’s picture

Correct and final solution: Install mailsystem.module and select "Standard" as E-Mail rendering theme in its settings. No further action required on our side, I think.
Please reopen, if this is not the final solution.

anybody’s picture

Status: Needs work » Closed (fixed)