Is there a way to include code in a template to set the pdf page orientation differently for a specific content type? Or some other way to do this?

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Not currently. The page orientation is a module-wide configuration that is not possible to change at each content type.

It would be possible to add code to do it, but I don't have the time to do it, nor do I think that that feature is in great demand.

João

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No further info in two weeks. Closing the issue.

Musicious’s picture

Hi,

I understand this topic was closed. I love your module and thank you for your work.

I do believe that this functionality would be amazing and could be very useful.

I very much need this. I am quite sure others may want this too.

Thanks

g.anedda’s picture

Hi, we have the same problem here, but we have arranged a "dirty" solution for the problem.
Modify the file print_pdf.pages.inc at this point (modifications delimited by comments)

<?php
function _print_pdf_tcpdf($print, $html, $filename) {
  global $base_url, $language;
  /* start modification */
  global $pdf_orientation;
 /* end mod */

  $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
  $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
  /* start modifications */
  if(isset($pdf_orientation))
	{
		$print_pdf_page_orientation = $pdf_orientation;
		unset($pdf_orientation);
	}
  else
  /* end modifications */
  $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
?>

And add this new piece

<?php
global $pdf_orientation;

$pdf_orientation = 'landscape'; /* landscape or portrait, choose the one that you need temporary */
?>

at the beginning of template pages of the content types that you need to have changed.

This dirty solution let you change temporary your chosen orientation to let you get a pdf oriented as you want.

Skispcs’s picture

Do you think it is possible to do this with a view?
I can currently print a View using this module but I want this one view to print in landscape while the regular pages print in portrait.
I tried adding

<?php
global $pdf_orientation;

$pdf_orientation = 'landscape'; /* landscape or portrait, choose the one that you need temporary */
?>

to the header as PHP input but that did not work.

Skispcs’s picture

Made this work by adding

<?php
global $pdf_orientation;

$pdf_orientation = 'landscape'; /* landscape or portrait, choose the one that you need temporary */
?>

to views-view.tpl.php

and I added the other part to the print_pdf.pages.inc.

I am sure that there is a better way by making a new custom views template but for now all of the views I need on this site should be in landscape so it works.

ice5nake’s picture

Category: support » feature
Status: Closed (fixed) » Active

I'd love to see this happen and it sounds like there have been several users requesting it.

The hack above uses global variables which feels really dirty to me. It seems like there should at least be a cleaner way to set this within your template.php file or even at the top of a template.

jcnventura’s picture

louis delacretaz’s picture

Issue summary: View changes

A quick way to set paper orientation per content is to add a hook_alter to print_pdf.pages.inc in each function that sets $print_pdf_page_orientation. ie _print_pdf_dompdf() _print_pdf_tcpdf() and _print_pdf_wkhtmltopdf()

function _print_pdf_dompdf($print, $html, $filename = NULL) {
  $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
  $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
  $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
  $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);

// Add this line
  drupal_alter('print_pdf_page_orientation_' . $print['type'],$print_pdf_page_orientation);

Then in your custom module add a hook_print_pdf_page_orientation_NODETYPE_alter to change the orientation

function MyModule_print_pdf_page_orientation_page_alter ($print_pdf_page_orientation){
  $print_pdf_page_orientation = 'Landscape';
}