KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Datatables PDF Export Button Column Alignment Issues #2931

Open cfsinc opened this topic on on Jan 7, 2023 - 14 comments

cfsinc commented on Jan 7, 2023

I cant align specific columns left, center and right on PDF Print

The code for datatables pdf printing is in the buttons.html.js and its settings are very limited.

Options title: filename: orientation: pageSize: header: footer: messageTop: messageBottom: customize: Custom is everything else but that is limited

Here is the code for that section: you obviously know the code because its your library but here is my problem. I need to control alignment of some of the columns and it does not allow for editing that.

Also at the bottom is my setup for my datatables PDF button and I have almost exhausted the custom settings as best I know how.

Im trying to add an array variable like columnalign: [] to your code and when you are evaluating if the row is odd or even I then check if the header is in my columnalign [name, age] and make those column cells align right.

So far I cant get this to work. PDF has never formatted and as far as I know I have to customize it a lot more in the future. Cal you help me with how I add alignment by an array of column titles?

Look at the bottom for my PDF button code. Its so much to get it to start looking good in datatables.

//
// PDF export - using pdfMake - http://pdfmake.org
//
DataTable.ext.buttons.pdfHtml5 = {
	className: 'buttons-pdf buttons-html5',

	available: function () {
		return window.FileReader !== undefined && _pdfMake();
	},

	text: function ( dt ) {
		return dt.i18n( 'buttons.pdf', 'PDF' );
	},

	action: function ( e, dt, button, config ) {
		this.processing( true );

		var that = this;
		var data = dt.buttons.exportData( config.exportOptions );
		var info = dt.buttons.exportInfo( config );
		var rows = [];

		if ( config.header ) {
			rows.push( $.map( data.header, function ( d ) {
				return {
					text: typeof d === 'string' ? d : d+'',
					style: 'tableHeader'
				};
			} ) );
		}

		for ( var i=0, ien=data.body.length ; i<ien ; i++ ) {
			rows.push( $.map( data.body[i], function ( d ) {
				if ( d === null || d === undefined ) {
					d = '';
				}
				return {
					text: typeof d === 'string' ? d : d+'',
					style: i % 2 ? 'tableBodyEven' : 'tableBodyOdd'
				};
			} ) );
		}

		if ( config.footer && data.footer) {
			rows.push( $.map( data.footer, function ( d ) {
				return {
					text: typeof d === 'string' ? d : d+'',
					style: 'tableFooter'
				};
			} ) );
		}

		var doc = {
			pageSize: config.pageSize,
			pageOrientation: config.orientation,
			content: [
				{
					table: {
						headerRows: 1,
						body: rows
					},
					layout: 'noBorders'
				}
			],
			styles: {
				tableHeader: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154',
					alignment: 'center'
				},
				tableBodyEven: {},
				tableBodyOdd: {
					fillColor: '#f3f3f3'
				},
				tableFooter: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154'
				},
				title: {
					alignment: 'center',
					fontSize: 15
				},
				message: {}
			},
			defaultStyle: {
				fontSize: 10
			}
		};

		if ( info.messageTop ) {
			doc.content.unshift( {
				text: info.messageTop,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.messageBottom ) {
			doc.content.push( {
				text: info.messageBottom,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.title ) {
			doc.content.unshift( {
				text: info.title,
				style: 'title',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( config.customize ) {
			config.customize( doc, config, dt );
		}

		var pdf = _pdfMake().createPdf( doc );

		if ( config.download === 'open' && ! _isDuffSafari() ) {
			pdf.open();
		}
		else {
			pdf.download( info.filename );
		}

		this.processing( false );
	},

	title: '*',

	filename: '*',

	extension: '.pdf',

	exportOptions: {},

	orientation: 'portrait',

	pageSize: 'A4',

	header: true,

	footer: false,

	messageTop: '*',

	messageBottom: '*',

	customize: null,

	download: 'download'
};

My PDF Code So Far

array(
       //datatables PDF Button Settings buttons.html5.js library from http://pdfmake.org/
        'filename'    => TITLE_NAME,
         'text'        => 'PDF',
         'extend'      => 'pdfHtml5',
         'orientation' => 'landscape',
         'pageSize'    => 'LETTER',
         'messageTop'  => 'Delinquency Report',
          'attr'        => array(
                  'title' => 'PDF',
                  'id'    => 'pdfButton'
          ),
	 // Control all additional default setting overwrites vendor folder js defaults
             'customize' => " function ( doc ) {
	 // These setting overwrite pdfHtml5 default settings called above.

	// Doc margin settings. There is no center table.
	// so I have to give it margins to center the table
	  doc.pageMargins = [85, 15, 15, 15];

       // defaulted entire doc to 10 font. Adjusting from there.
          doc.defaultStyle.fontSize = 10;

	// Top detailed title size setting
	doc.styles.title.fontSize = 10;

	// Table Header Settings Changes
	doc.styles.tableHeader.fontSize = 10;
	//doc.styles.tableHeader.alignment = 'center'

	// Font default size for table body
	doc.styles.tableBodyEven.fontSize = 8;
	doc.styles.tableBodyOdd.fontSize = 8;

	// Now to get control over the column alignment
											
       }"
       // Additional Options
       //'exportOptions' => ''
       //'header'=>'true', //default true
       //'footer'=>'true', //default false
      //"messageBottom"=>$title,
      //"className" => $pdfClass,
      //'text'=>'<i class="fa fa-file-pdf-o"></i>',
      //'autoPrint'=>'true', //this works in datatables but not koolreports
 ),

cfsinc commented on Jan 7, 2023

My thoughts were to alter this section of your code and add checks for header names in an array and if found make those cells alignment: 'right' but so far i can not get it to work.

cfsinc commented on Jan 7, 2023

Here is some code I been trying by trying to grab the column title by name and then apply the alignment right to body and footer but its not working. Nothing so far is working. I can only make the whole row align right

//
// PDF export - using pdfMake - http://pdfmake.org
//
DataTable.ext.buttons.pdfHtml5 = {
	className: 'buttons-pdf buttons-html5',

	available: function () {
		return window.FileReader !== undefined && _pdfMake();
	},

	text: function ( dt ) {
		return dt.i18n( 'buttons.pdf', 'PDF' );
	},

	action: function ( e, dt, button, config ) {
		this.processing( true );

		var that = this;
		var data = dt.buttons.exportData( config.exportOptions );
		var info = dt.buttons.exportInfo( config );
		var rows = [];

		if ( config.header ) {
			rows.push( $.map( data.header, function ( d ) {
				return {
					text: typeof d === 'string' ? d : d+'',
					style: 'tableHeader'
				};
			} ) );
		}

		var headerNames = ['Bal', 'Pastdue', '6'];

		rows.push( $.map( data.body[i], function ( d, index ) {
		  if ( d === null || d === undefined ) {
			d = '';
		  }
		  return {
			text: typeof d === 'string' ? d : d+'',
			style: i % 2 ? 'tableBodyEven' : 'tableBodyOdd',
			alignment: headerNames.indexOf(data.header[index]) !== -1 ? 'right' : 'left'
		  };
		} ) );

		if ( config.footer && data.footer) {
			rows.push( $.map( data.footer, function ( d, index ) {
			  return {
				text: typeof d === 'string' ? d : d+'',
				style: 'tableFooter',
				alignment: index === 1 || index === 2 ? 'right' : 'left'
			  };
			} ) );
		  }

		var doc = {
			pageSize: config.pageSize,
			pageOrientation: config.orientation,
			content: [
				{
					table: {
						headerRows: 1,
						body: rows
					},
					layout: 'noBorders'
				}
			],
			styles: {
				tableHeader: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154',
					alignment: 'center'
				},
				tableBodyEven: {},
				tableBodyOdd: {
					fillColor: '#f3f3f3'
				},
				tableFooter: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154'
				},
				title: {
					alignment: 'center',
					fontSize: 15
				},
				message: {}
			},
			defaultStyle: {
				fontSize: 10
			}
		};

		if ( info.messageTop ) {
			doc.content.unshift( {
				text: info.messageTop,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.messageBottom ) {
			doc.content.push( {
				text: info.messageBottom,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.title ) {
			doc.content.unshift( {
				text: info.title,
				style: 'title',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( config.customize ) {
			config.customize( doc, config, dt );
		}

		var pdf = _pdfMake().createPdf( doc );

		if ( config.download === 'open' && ! _isDuffSafari() ) {
			pdf.open();
		}
		else {
			pdf.download( info.filename );
		}

		this.processing( false );
	},

	title: '*',

	filename: '*',

	extension: '.pdf',

	exportOptions: {},

	orientation: 'portrait',

	pageSize: 'A4',

	header: true,

	footer: false,

	messageTop: '*',

	messageBottom: '*',

	customize: null,

	download: 'download'
cfsinc commented on Jan 7, 2023

i did try it as a separate function and not tied into the current functions but it didnt work for me. Im not so great at javascript but this is one of those things helping me learn. Also maybe a stupid question but why cant I console log to screen? none of my console logs show?

Sebastian Morales commented on Jan 9, 2023

Ok, I see. No console log output might indicate your extending pdf html5 button did not execute the action function. Let's try a simple customized action pdf button right inside DataTables' create code like this:

DataTables::create(array(
    ...
    "plugins" => [ "Buttons",...],
    "options" => array(
                    "buttons" => [
                        [
                            "extend" => 'pdfHtml5', 
                            // "orientation" => "landscape",
                            // "pageSize" => "A0",
                            "action" => "function ( e, dt, button, config ) {
                                console.log(e, dt, button, config); //open your page's dev tool to see this console.log output
                                ...// your customized commands
                            }" //wrap the javascript function in quotes
                        ],
    )
));

Let us know the result. Tks,

cfsinc commented on Jan 9, 2023

ok i will try your suggestion for console log but for sure the code is executing because me trying to edit your core file under datagrid/Datatables/Buttons-1.6.2/js/buttons.html5.js class does make the pdf output change. I just cant yet figure out how to get control over column alignment by array of names or index numbers yet. Right now the only styling that is applied to the table is row odd even coloring. Any help on how I add the ability to align specific columns left, right or center would be great?

//
// PDF export - using pdfMake - http://pdfmake.org
//
DataTable.ext.buttons.pdfHtml5 = {
	className: 'buttons-pdf buttons-html5',
cfsinc commented on Jan 9, 2023

you were right, its not using the buttons.html5.js its using the minify buttons.html5.min.js version

So I will either find the code that calls the min.js and change it to unminify file or make changes a new minify js file?

I cant believe no one has needed to format their PDFs better in datatables integrated buttons and run into this. Maybe they have all been experts in javascript :)

cfsinc commented on Jan 9, 2023

ok i got it. I have it working.

I will post the new buttons.html5.js once I have all the new options created for it and also document how to use it so you can add it with all the new formatting options to a future release if you want.

cfsinc commented on Jan 10, 2023

Update: Im going to make the the following changes. columnAlignments will be called columnBodyAlign as its for the column body and not the header alignment.

I can now control the column alignment from the datatables PDF button setup without custom code. See the new option called columnAlignments array and you call your column title name and then the alignment. Also is the new code for the buttons.html5.js so replace the old code and create a new buttons.html5.min.js from the new buttons.html5.js and thats it.

array(
//datatables PDF Button Settings buttons.html5.js library from pdfmake.org/
'filename'    => TITLE_NAME,
'text'        => 'PDF',
'extend'      => 'pdfHtml5',
'orientation' => 'landscape',
'pageSize'    => 'LETTER',
'messageTop'  => 'Delinquency Report',
'columnAlignments' => array(
                        'Acc'  => 'right',
                        'Name' => 'left',
                        'Bal'  => 'right',
                        'Past' => 'right',
),



Here is the new code for the PDF Export located in the buttons.html5.js

//
// PDF export - using pdfMake - http://pdfmake.org
//
DataTable.ext.buttons.pdfHtml5 = {
	className: 'buttons-pdf buttons-html5',

	available: function () {
		return window.FileReader !== undefined && _pdfMake();
	},

	text: function ( dt ) {
		return dt.i18n( 'buttons.pdf', 'PDF' );
	},

	action: function ( e, dt, button, config ) {
		this.processing( true );

		var that = this;
		var data = dt.buttons.exportData( config.exportOptions );
		var info = dt.buttons.exportInfo( config );
		var rows = [];
		var alignment = 'left';
		var columnAlignments = config.columnAlignments;

		if ( config.header ) {
			rows.push( $.map( data.header, function ( d ) {
				return {
					text: typeof d === 'string' ? d : d+'',
					style: 'tableHeader'
				};
			} ) );
		}

		for ( var i=0, ien=data.body.length ; i<ien ; i++ ) {
			rows.push( $.map( data.body[i], function ( d, j ) {
				var columnName = data.header[j];
				var alignment = columnAlignments[columnName] || "left";
				if ( d === null || d === undefined ) {
					d = '';
				}
				return {
					text: typeof d === 'string' ? d : d+'',
					style: i % 2 ? 'tableBodyEven' : 'tableBodyOdd',
					alignment: alignment
				};
			} ) );
		}

		if ( config.footer && data.footer) {
			rows.push( $.map( data.footer, function ( d ) {
				return {
					text: typeof d === 'string' ? d : d+'',
					style: 'tableFooter'
				};
			} ) );
		}

		var doc = {
			pageSize: config.pageSize,
			pageOrientation: config.orientation,
			content: [
				{
					table: {
						headerRows: 1,
						body: rows
					},
					layout: 'noBorders'
				}
			],
			styles: {
				tableHeader: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154',
					alignment: 'center'
				},
				tableBody: {
					alignment: alignment
				},
				tableBodyEven: {},
				tableBodyOdd: {
					fillColor: '#f3f3f3'
				},
				tableFooter: {
					bold: true,
					fontSize: 11,
					color: 'white',
					fillColor: '#2d4154'
				},
				title: {
					alignment: 'center',
					fontSize: 15
				},
				message: {}
			},
			defaultStyle: {
				fontSize: 10
			}
		};

		if ( info.messageTop ) {
			doc.content.unshift( {
				text: info.messageTop,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.messageBottom ) {
			doc.content.push( {
				text: info.messageBottom,
				style: 'message',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( info.title ) {
			doc.content.unshift( {
				text: info.title,
				style: 'title',
				margin: [ 0, 0, 0, 12 ]
			} );
		}

		if ( config.customize ) {
			config.customize( doc, config, dt );
		}

		var pdf = _pdfMake().createPdf( doc );

		if ( config.download === 'open' && ! _isDuffSafari() ) {
			pdf.open();
		}
		else {
			pdf.download( info.filename );
		}

		this.processing( false );
	},

	title: '*',

	filename: '*',

	extension: '.pdf',

	exportOptions: {},

	orientation: 'portrait',

	pageSize: 'A4',

	header: true,

	footer: false,

	messageTop: '*',

	messageBottom: '*',

	customize: null,

	download: 'download',

	columnAlignments: {}
};


cfsinc commented on Jan 10, 2023

the only easily configurable options that PDF print button built into datatables are title, filename,orientation, pageSize, header, footer true or false, Message Top, Message Bottom.

All these important things need to be setup in custom code like below but they are setting that should be configurable without custom code like the alignment config option i had to add to the core code.

Im going to add all these configuration options also and then post the code. If you guys want to use it in a future release it will help a lot of people. I will also post how to use all of it when its done.

'customize' => " function ( doc ) {
		// These setting overwrite pdfHtml5 default settings
                // Doc margin settings. There is no center table.
		// so I have to give it margins to center the table
		doc.pageMargins = [85, 15, 15, 15];

		// defaulted entire doc to 10 font. Adjusting from there.
                doc.defaultStyle.fontSize = 10;

		// Top detailed title size setting
		doc.styles.title.fontSize = 10;

		// Table Header Settings Changes
		doc.styles.tableHeader.fontSize = 10;
		//doc.styles.tableHeader.alignment = 'center'

		// Font default size for table body
		doc.styles.tableBodyEven.fontSize = 8;
		doc.styles.tableBodyOdd.fontSize = 8;
		//doc.styles.tableBodyOdd.alignment = 'right'

		// Now to get control over the column alignment
}"


cfsinc commented on Jan 10, 2023

sorry that was not the way to go with this! there is no reason to change your code. Im going to create a new

DataTable.ext.buttons.pdfHtml5FullControl or whatever for the name and add all the following as configurable settings. Then all you have to do to use it is change 'extend' => 'pdfHtml5', to pdfHtml5FullControl :)

Well that and replace the buttons.html5.js and min.js with the new files and people can have both old and new :)

Page
pageMargins: [ 40, 60, 40, 60 ],

Title
bold: true,
italics: false,
fontSize: 11,
color: 'white',
fillColor: '#2d4154',
alignment: 'center'

Table Header
bold: true,
italics: false,
fontSize: 11,
color: 'black',

Table Body
bold: true,
italics: false,
fontSize: 11,
color: 'white',
fillColor: '#2d4154',
column alignment: '',
lineHeight: '',

Table Footer
bold: true,
italics: false,
fontSize: 11,
color: 'white',
fillColor: '#2d4154',
alignment: 'center'

Message Top
bold: true,
italics: false,
fontSize: 11,
color: 'white',
fillColor: '#2d4154',
alignment: 'center'

Message Bottom
bold: true,
fontSize: 11,
italics: false,
color: 'white',
fillColor: '#2d4154',
alignment: 'center'

Table General
layout
noBorders
headerLineOnly
lightHorizontalLines
width: ‘’,

Fonts
pdfMake.fonts = {
  Courier: {
    normal: 'Courier',
    bold: 'Courier-Bold',
    italics: 'Courier-Oblique',
    bolditalics: 'Courier-BoldOblique'
  },
  Helvetica: {
    normal: 'Helvetica',
    bold: 'Helvetica-Bold',
    italics: 'Helvetica-Oblique',
    bolditalics: 'Helvetica-BoldOblique'
  },
  Times: {
    normal: 'Times-Roman',
    bold: 'Times-Bold',
    italics: 'Times-Italic',
    bolditalics: 'Times-BoldItalic'
  },
  Symbol: {
    normal: 'Symbol'
  },
  ZapfDingbats: {
    normal: 'ZapfDingbats'
  }
};
 
var docDefinition = {
  content: [
    'First paragraph',
    'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines',
  ],
  defaultStyle: {
    font: 'Helvetica'
  }
};

cfsinc commented on Jan 10, 2023

all my custom code for datatables pdf generation now moved to javascript file and easily called now as PDF options.

All this custom code mess is gone and new option calls below

// Control all additional default setting overwrites vendor folder js defaults
'customize' => " function ( doc ) {
			// These setting overwrite pdfHtml5 default settings called above.

		        // Doc margin settings. There is no center table.
			// so I have to give it margins to center the table
			//doc.pageMargins = [85, 15, 15, 15];

			// defaulted entire doc to 10 font. Adjusting from there.
                        //doc.defaultStyle.fontSize = 10;

			// Top detailed title size setting
			//doc.styles.title.fontSize = 10;

			// Table Header Settings Changes
			//doc.styles.tableHeader.fontSize = 10;
			//doc.styles.tableHeader.alignment = 'center'

			// Font default size for table body
	                //doc.styles.tableBodyEven.fontSize = 8;
	               //doc.styles.tableBodyOdd.fontSize = 8;
	              //doc.styles.tableBodyOdd.alignment = 'right'
}"

array(
      //datatables PDF Button Settings buttons.html5.js library from pdfmake.org/
      'filename' => TITLE_NAME,
      'text' => 'PDF',
      'extend' => 'pdfHtml5Advanced',
      'orientation' => 'landscape',
      'pageSize' => 'LETTER',
      'messageTop' => 'Delinquency Report',
      'colBodyAlign' => array(
                            'Acc' => 'right',
                             'Name' => 'left',
                             'Bal' => 'right',
                             'Past' => 'right',
	 ),
        'pageMargins' => [85,15,15,15],
         'defaultFontSize' => '20',
         'titleFontSize' => '10',
          'titleAlignment' => 'center',
          'tableHeaderFontSize' => '10',
          'tableBodyFontSize' => '8',
          'attr' => array(
                     'title' => 'PDF',
                      'id'    => 'pdfButton'
          ),
),

Have a lot more configuration to add but here is the latest version of the code that supports all of the above.

/*
*PDF export - using pdfMake - http://pdfmake.org
* Advanced Configuration Options for Koolrepots Datatables PDF Button
*
* Column Allignment by header name list aray and alignment - usage
* 	'colBodyAlign' => array(
*			'Acc'  => 'right',
*			'Name' => 'left',
*			'Bal'  => 'right',
*			'Past' => 'right',
*	),
*       'pageMargins'         => [85,15,15,15],
*	'defaultFontSize'     => '20',
*	'titleFontSize'       => '10',
*	'titleAlignment'      => 'center',
*	'tableHeaderFontSize' => '10',
*	'tableBodyFontSize'   => '8',
*
*/
	DataTable.ext.buttons.pdfHtml5Advanced = {
		className: 'buttons-pdf-advanced buttons-html5-advanced',

		available: function () {
			return window.FileReader !== undefined && _pdfMake();
		},

		text: function ( dt ) {
			return dt.i18n( 'buttons.pdf', 'PDF' );
		},

		action: function ( e, dt, button, config ) {
			this.processing( true );

			var that = this;
			var data = dt.buttons.exportData( config.exportOptions );
			var info = dt.buttons.exportInfo( config );
			var rows = [];
			var alignment = 'left';
			var colBodyAlign = config.colBodyAlign;

			if ( config.header ) {
				rows.push( $.map( data.header, function ( d ) {
					return {
						text: typeof d === 'string' ? d : d+'',
						style: 'tableHeader'
					};
				} ) );
			}

			for ( var i=0, ien=data.body.length ; i<ien ; i++ ) {
				rows.push( $.map( data.body[i], function ( d, j ) {
					var columnName = data.header[j];
					var alignment = colBodyAlign[columnName] || "left";
					if ( d === null || d === undefined ) {
						d = '';
					}
					return {
						text: typeof d === 'string' ? d : d+'',
						style: i % 2 ? 'tableBodyEven' : 'tableBodyOdd',
						alignment: alignment
					};
				} ) );
			}

			if ( config.footer && data.footer) {
				rows.push( $.map( data.footer, function ( d ) {
					return {
						text: typeof d === 'string' ? d : d+'',
						style: 'tableFooter'
					};
				} ) );
			}

			var doc = {
				pageSize: config.pageSize,
				pageOrientation: config.orientation,
				pageMargins: config.pageMargins,
				content: [
					{
						table: {
							headerRows: 1,
							body: rows
						},
						layout: 'noBorders'
					}
				],
				styles: {
					tableHeader: {
						bold: true,
						fontSize: config.tableHeaderFontSize,
						color: 'white',
						fillColor: '#2d4154',
						alignment: 'center'
					},
					tableBody: {
						alignment: alignment
					},
					tableBodyEven: {
						fontSize: config.tableBodyFontSize
					},
					tableBodyOdd: {
						fillColor: '#f3f3f3',
						fontSize: config.tableBodyFontSize
					},
					tableFooter: {
						bold: true,
						fontSize: 11,
						color: 'white',
						fillColor: '#2d4154'
					},
					title: {
						alignment: config.titleAlignment,
						fontSize: config.titleFontSize
					},
					message: {}
				},
				defaultStyle: {
					fontSize: config.fontDefaultFontSize
				}
			};

			if ( info.messageTop ) {
				doc.content.unshift( {
					text: info.messageTop,
					style: 'message',
					margin: [ 0, 0, 0, 12 ]
				} );
			}

			if ( info.messageBottom ) {
				doc.content.push( {
					text: info.messageBottom,
					style: 'message',
					margin: [ 0, 0, 0, 12 ]
				} );
			}

			if ( info.title ) {
				doc.content.unshift( {
					text: info.title,
					style: 'title',
					margin: [ 0, 0, 0, 12 ]
				} );
			}

			if ( config.customize ) {
				config.customize( doc, config, dt );
			}

			var pdf = _pdfMake().createPdf( doc );

			if ( config.download === 'open' && ! _isDuffSafari() ) {
				pdf.open();
			}
			else {
				pdf.download( info.filename );
			}

			this.processing( false );
		},

		title: '*',

		filename: '*',

		extension: '.pdf',

		exportOptions: {},

		orientation: 'portrait',

		pageSize: 'A4',

		header: true,

		footer: false,

		messageTop: '*',

		messageBottom: '*',

		customize: null,

		download: 'download',

		colBodyAlign: {},

		pageMargins: {},

		defaultFontSize: '10',

		titleFontSize: '10',

		titleAlignment: 'center',

		tableHeaderFontSize: '10',

		tableBodyFontSize: '8',

	};

Sebastian Morales commented on Jan 10, 2023

Such great effort and wonderful solution from your side. I'm sure other users would benefit from your solution in case they need to customize DataTables' PDF button printing. Tks a lot,

On another note, I think you could totally push this customized plugin to DataTables' plugins registry as an open source contributor.

cfsinc commented on Jan 10, 2023

Yes I will push it to datatables plugins when im done. everything was working great when I ran code under the the unminified buttons.html5.js but I ran into some trouble after I minified the file back to buttons.html5.min.js

I needed to edit some code in the DataTables directory datatables.min.js but you dont include a datatables.js in your build files or the datatables.css in your build file. you only have the minifies versions.

I had to go to datatables and download their source code to have unminified files to edit. It would be very helpful if you added those files to your build or its not possible to fix the references to the button files they have in them.

I would have to keep my buttons.html5.js unminified to work and also keep the call to the unminified file left in the DataTables.php

Sebastian Morales commented on Jan 11, 2023

Yes, we will consider adding the unminified DataTables' js and css files to koolreport/datagrid package as well as an option to load those instead of the minified ones. Rgds,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

DataGrid