View preferences

Add-On View preferences

Informations

Author: Michel Poulain
License: FPDF

Description

This script allows to set some viewer preferences.

DisplayPreferences(string preferences)

The available settings are (case-sensitive):
  • FullScreen: displays the document full-screen
  • HideMenubar: hides the menu
  • HideToolbar: hides all toolbars
  • HideWindowUI: hides all window elements (scrollbars, navigation controls, bookmarks...)
  • DisplayDocTitle: displays the title of the document instead of the file name
  • CenterWindow: centers the window
  • FitWindow: sizes the window (when not maximized) to fit the page
Note: these settings are ignored when the PDF is displayed in a browser.

Source

<?php
require('fpdf.php');

class PDF_ViewPref extends FPDF {

protected $DisplayPreferences = '';

function DisplayPreferences($preferences) {
    $this->DisplayPreferences = $preferences;
}

function _putcatalog()
{
    parent::_putcatalog();
    if(is_int(strpos($this->DisplayPreferences, 'FullScreen')))
        $this->_put('/PageMode /FullScreen');
    if($this->DisplayPreferences) {
        $this->_put('/ViewerPreferences<<');
        if(is_int(strpos($this->DisplayPreferences, 'HideMenubar')))
            $this->_put('/HideMenubar true');
        if(is_int(strpos($this->DisplayPreferences, 'HideToolbar')))
            $this->_put('/HideToolbar true');
        if(is_int(strpos($this->DisplayPreferences, 'HideWindowUI')))
            $this->_put('/HideWindowUI true');
        if(is_int(strpos($this->DisplayPreferences, 'DisplayDocTitle')))
            $this->_put('/DisplayDocTitle true');
        if(is_int(strpos($this->DisplayPreferences, 'CenterWindow')))
            $this->_put('/CenterWindow true');
        if(is_int(strpos($this->DisplayPreferences, 'FitWindow')))
            $this->_put('/FitWindow true');
        $this->_put('>>');
    }
}
}
?>

Example

<?php
require('viewpref.php');

$pdf=new PDF_ViewPref();
$pdf->SetDisplayMode('fullpage');
$pdf->DisplayPreferences('HideMenubar, HideToolbar, HideWindowUI');
$pdf->AddPage();
$pdf->SetFont('Arial', '', 16);
$pdf->Write(6, 'Only the document should appear, no interface elements.');
$pdf->Output();
?>
View the result here.

Download

ZIP | TGZ