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.
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.
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.
3) Prepare your view.pdf.php file. In this file, you will need to output your pdf.PHP Code:// For example: action 'PrintPDF' to access '<YOUR MODULE>/views/view.pdf.php'
function action_PrintPDF() {
$this->view = 'pdf';
}
4) Final step, add a custom button "PDF" on your detail view page that fire 'PrintPDF' action.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_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle($bean->name);
$pdf->SetHeaderData(null, null, $bean->name, null);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 12));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_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($cssHTML, true, false, false, false, '');
$pdf->writeHTML($detailViewHTML, true, false, false, false, '');
$pdf->Output('detailview.pdf', 'I');
}
}
Edit 'detailviewdefs.php':
This example is simple, without good css style but following your detail view layout.PHP Code:'buttons' => array (
0 => 'EDIT',
1 => 'DUPLICATE',
2 => 'DELETE',
3 => 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);">',
),
),
Note: All the subpanels are not included in the pdf export.
Pan Jun![]()
EVERYTHING IS CLOUD!
SugarForge Project: Manage your Objectives
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks