TYPO3 Extension: Create PDF File

I am trying to make an extension from Kickstarter that overrides normal page rendering and displays the PDF. For this he uses FPDF. But I'm not sure how to do this. I tried to do this, but it didn't work:

<?php

// require_once(PATH_tslib . 'class.tslib_pibase.php');

class tx_ishurkunde_pi1 extends tslib_pibase {
    public $prefixId      = 'tx_ishurkunde_pi1';
    public $scriptRelPath = 'pi1/class.tx_ishurkunde_pi1.php';
    public $extKey        = 'ish_urkunde';
    public $pi_checkCHash = TRUE;

    public function main($content, array $conf) {

        if (!t3lib_extMgm::isLoaded('fpdf')) return "Error!";

        $pdf = new FPDF();
        $pdf->AddPage();
        $content = $pdf->Output('', 'S');
        return $content;

    }
}
?>

      

It still continues rendering a regular web template. What am I missing?

FYI, I am not trying to display HTML as PDF. Im trying to generate a PDF from scratch using url parameters are text variables.

+3


source to share


1 answer


As I understand it, your goal is to make PDF instead of page elements.

Your current approach won't work as you are embedding the plugin into the page. The plugin's return value is then returned to the TYPO3 content parser, and if the page has finished parsing, it is displayed. It doesn't have any part where you can drop the whole page; At least it is not intended, and you should not (although there are extensions that do this).

The eID approach would be to create an eID script (look at dd_googlesitemap) that is called with a GET parameter and displays only what you need. There you can basically do whatever you want.

In the extension, ext_localconf.php

you register the eID script, for example:

$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$_EXTKEY] = "EXT:{$_EXTKEY}/path/to/my/EIDHandler.php";

      

Example of eID handler structure:



class Tx_MyExt_EIDHandler
{
  public function main()
  {
    // Your code here
  }
}

$output = t3lib_div::makeInstance('Tx_MyExt_EIDHandler');
$output->main();

      

To call your eID script in the frontend, you add the appropriate GET parameters like http://example.com/index.php?eID=tx_myext . This is the key of the array you defined in ext_localconf.php

(in my example it is $_EXTKEY

, but it can be any string).

Plugin / type approach . TemplaVoila does it: you create a PAGE type and call user_func

that does your stuff. This would be the fastest approach because you already have the plugin. The important thing is that you create your own page type with just your plugin.

TypoScript example:

specialPage = PAGE
specialPage {
  type = 2
  10 = USER
  10.userFunc = tx_myextension_pi1->myFunc
}

      

After that, you can call your new page http://example.com/index.php?type=2 . However, headers etc. Are still displayed and you may need to remove them.

0


source







All Articles