Results 1 to 2 of 2

Thread: Dynamic PDF in Detail View style

  1. #1
    hiko is offline Sugar Community Member
    Join Date
    Aug 2008
    Posts
    110

    Question Dynamic PDF in Detail View style

    Hi,

    I have 3 panel in my detail view of my custom module.

    I want to export data with same detail view table structure and style in pdf using tcpdf library in sugar.

    Do we have any reference example or similar example for same.

    - Thanks.
    Last edited by hiko; 2012-01-09 at 02:21 PM.

  2. #2
    PanJun is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Shanghai
    Posts
    50

    Default Re: Dynamic PDF in Detail View style

    Hello hiko,

    I can give you a SugarCE solution.

    1) Download TCPDF lib and copy it under your module.

    2) Prepare a controller.php for this module and one action to access your pdf view.
    PHP Code:
            // For example: action 'PrintPDF' to access '<YOUR MODULE>/views/view.pdf.php'
        
    function action_PrintPDF() {
            
    $this->view 'pdf';
        } 
    3) Prepare your view.pdf.php file. In this file, you will need to output your pdf.
    PHP Code:
    require_once('include/MVC/View/SugarView.php');
    require_once(
    'modules/<YOUR_MODULE>/tcpdf/config/lang/eng.php');
    require_once(
    'modules/<YOUR_MODULE>/tcpdf/tcpdf.php');

    class <
    YOUR_MODULE>ViewPdf extends SugarView {

        function <
    YOUR_MODULE>ViewPdf() {
            
    parent::SugarView();
        }

        function 
    process() {
            
    $this->printDetailViewPage();
        }

        function 
    printDetailViewPage() {
            
    $bean= new <YOUR_MODULE_SUGARBEAN>();
            
    $bean->retrieve($_REQUEST['record']);

            
    $pdf = new TCPDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
            
    $pdf->SetCreator(PDF_CREATOR);
            
    $pdf->SetTitle($bean->name);

            
    $pdf->SetHeaderData(nullnull$bean->namenull);

            
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN''12));
            
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
            
    $pdf->SetMargins(PDF_MARGIN_LEFT10PDF_MARGIN_RIGHT);
            
    $pdf->SetHeaderMargin(5);
            
    $pdf->setFontSubsetting(true);

            
    // set font
            
    $pdf->SetFont('helvetica'''10);

            
    // add a page
            
    $pdf->AddPage();

            
    $view ViewFactory::loadView("detail""<YOUR_MODULE>"$bean, array(), "");
            
    $view->options = array (
                
    'show_header' => false,
                
    'show_title' => false,
                
    'show_search' => false,
                
    'show_footer' => false,
                
    'show_javascript' => false,
                
    'json_output' => false,
                
    'view_print' => false
            
    );

            
    $view->preDisplay();
            
    // Remove buttons for PDF
            
    $view->dv->defs['templateMeta']['form']['headerTpl'] = "";

            
    // detail view, sugar_field
            
    $cssHTML "
            <!-- DETAIL VIEW OF CSS STYLE -->
            <style>
                /* detail view */
                .detail.view,
                .detail table,
                table.detail
                {
                    padding: 0;
                    width: 100%;
                }
                .detail tr.pagination td
                {
                    padding-top: 4px;
                    text-align: right;
                    vertical-align: middle;
                }
                .detail table tr.pagination td
                {
                    padding-bottom: 4px;
                }
                .detail td > table tr td
                {
                    border: none;
                }
            </style>
            "
    ;

            
    $detailViewHTML $view->displayHTML(false);

            
    $pdf->writeHTML($cssHTMLtruefalsefalsefalse'');
            
    $pdf->writeHTML($detailViewHTMLtruefalsefalsefalse'');
            
    $pdf->Output('detailview.pdf''I');
        }

    4) Final step, add a custom button "PDF" on your detail view page that fire 'PrintPDF' action.
    Edit 'detailviewdefs.php':
    PHP Code:
                    'buttons' => array (
                          
    => 'EDIT',
                          
    => 'DUPLICATE',
                          
    => 'DELETE',
                          
    => array (
                              
    'customCode' => '<input title="PDF" class="button" type="button" name="PDF" value="PDF" id="pdf_button" onclick="open_popup(\'PDF_Print\',\'800\',\'900\',\'&module=<YOUR_MODULE>&action=PrintPDF&record={$fields.id.value}\',true,false);">',
                          ),
                    ), 
    This example is simple, without good css style but following your detail view layout.
    Note: All the subpanels are not included in the pdf export.

    Pan Jun
    EVERYTHING IS CLOUD!
    SugarForge Project: Manage your Objectives

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 2011-02-09, 10:57 AM
  2. Inbox-style view for case notes
    By adampage in forum Feature Requests
    Replies: 1
    Last Post: 2010-09-20, 11:59 AM
  3. Replies: 1
    Last Post: 2009-03-04, 10:56 AM
  4. Replies: 13
    Last Post: 2007-10-04, 05:53 AM
  5. Replies: 0
    Last Post: 2006-05-04, 01:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •