0

I need to customize the .pdf invoice for my prestashop,

The problem is that is too tedious to do it:

  • Change .tpl
  • Generate .pdf
  • Preview changes

I would like to ( in the meantime ) to output the invoice as HTML and to bee able to inspect the elements with the developer tools..

Any workaround? I guess that with an override would be posible, but I didn't find anything in google..

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

2 Answers2

3

You can get an approximation of the html before the pdf render by overriding the render function in classes/pdf/PDF.php to:

public function render($display = true)
    {
        $render = false;
        $this->pdf_renderer->setFontForLang(Context::getContext()->language->iso_code);
        foreach ($this->objects as $object) {
            $this->pdf_renderer->startPageGroup();
            $template = $this->getTemplateObject($object);
            if (!$template) {
                continue;
            }

            if (empty($this->filename)) {
                $this->filename = $template->getFilename();
                if (count($this->objects) > 1) {
                    $this->filename = $template->getBulkFilename();
                }
            }

            $template->assignHookData($object);

            // for previewing html
            echo $template->getHeader();
            echo $template->getContent();
            echo $template->getFooter();
            exit;

            $this->pdf_renderer->createHeader($template->getHeader());
            $this->pdf_renderer->createFooter($template->getFooter());
            $this->pdf_renderer->createPagination($template->getPagination());
            $this->pdf_renderer->createContent($template->getContent());
            $this->pdf_renderer->writePage();
            $render = true;

            unset($template);
        }

        if ($render) {
            // clean the output buffer
            if (ob_get_level() && ob_get_length() > 0) {
                ob_clean();
            }
            return $this->pdf_renderer->render($this->filename, $display);
        }
    }

Added the echo for the header, content and footer. For pagination I'm not sure how it would work, haven't tested.

sadlyblue
  • 2,992
  • 7
  • 22
  • 19
0

I found this one : https://github.com/itext/rups/.
If you want more details we've got a post in StackOverflow :
Best tool tool for inspecting PDF files?

Benjamin.G
  • 26
  • 2