PDF-API for Magento Developers

Magento developers can use my Advanced Invoice Layout Extension to either customize the default look'n'feel of the Magento PDF invoices, shipments and creditmemos or alternatively to implement their own PDF printing extension based on the ready-to-use vianetz PDF API.

Implement your own PDF Extension

Together with the Advanced Invoice Layout Extension we bundle the vianetz PDF Engine API that enables you as a developer to build your custom solution for PDF printing, e.g. to allow users to save the product detail page in your Magento store as PDF file or to create completely individual PDF documents with easy HTML/CSS styling.
Therefore we describe the public API of the vianetz PDF Engine as follows:

Class Vianetz_Pdf_Model_Pdf:

  • addDocument(Vianetz_Pdf_Model_Document_Interface) Add a new document to the PDF instance
  • getContents() Return the PDF file contents
  • saveToFile(string) Generate and save the current PDF contents to specified file name

The magic lies in the Vianetz_Pdf_Model_Document_Interface which asks you to implement the following method:

  • getHtmlContents() Return the HTML contents that should be converted into PDF

Sample Usage

<?php

class Your_Document implements Vianetz_Pdf_Model_Document_Interface {
    /**
     * This fetches the product detail page content for product id 1.
     * You can return any kind of HTML content here.
     */
    public function getHtmlContents()
    {
        $block = Mage::getBlockSingleton('catalog/product_view')
            ->setProductId(1);
        $block->setTemplate('catalog/product/view.phtml');

        return $block->toHtml();
    }
}

// Create a new pdf instance.
$pdf = new Vianetz_Pdf_Model_Pdf();

// Add our document class. You can add as many documents as you like
// as they will all be merged into one PDF file.
$pdf->addDocument(new Your_Document());

// Save the resulting PDF to file test.pdf - That's it :-)
$pdf->saveToFile('test.pdf');

Please get in touch with me if you have any questions.