Thanks PGoldman for your input. and i must agree with you that although the export to PDF functionality is useful and helpful, however, I feel that it is not complete and does not support scenarios that are slightly diverting from the standard way of using the DHTMLX Grid component (things like Orientation, Custom Colors, footers…etc). I hope that the DHTMLX guys are reading this post and will provide a fix for all the issues above and I am sure there are many more listen in this forum.
Having said that, I found that the only way to control the orientation of the page is by modifying the toPDF method inside the dhtmlxgrid_export.js file to pass extra parameter called ‘orientation’ to the function that will then get passed to the PDFGenerator servlet.
Below is my modification to the toPDF method
dhtmlXGridObject.prototype.toPDF=function(url,mode,orientation,header,footer,rows,target){
mode = mode || "color";
var full_color = mode == "full_color";
var grid = this;
grid._asCDATA = true;
if (typeof(target) === 'undefined')
this.target = " target=\"_blank\"";
else
this.target = target;
eXcell_ch.prototype.getContent = function(){
return this.getValue();
};
eXcell_ra.prototype.getContent = function(){
return this.getValue();
};
function xml_top(profile) {
var spans = [];
for (var i=1; i<grid.hdr.rows.length; i++){
spans[i]=[];
for (var j=0; j<grid._cCount; j++){
var cell = grid.hdr.rows[i].childNodes[j];
if (!spans[i][j])
spans[i][j]=[0,0];
if (cell)
spans[i][cell._cellIndexS]=[cell.colSpan, cell.rowSpan];
}
}
var xml = "<rows profile='"+profile+"'";
if (header)
xml+=" header='"+header+"'";
if (footer)
xml+=" footer='"+footer+"'";
if (orientation)
xml+=" orientation='"+orientation+"'";
xml+="><head>"+grid._serialiseExportConfig(spans).replace(/^<head/,"<columns").replace(/head>$/,"columns>");
for (var i=2; i < grid.hdr.rows.length; i++) {
var empty_cols = 0;
var row = grid.hdr.rows[i];
var cxml="";
for (var j=0; j < grid._cCount; j++) {
if ((grid._srClmn && !grid._srClmn[j]) || (grid._hrrar[j])) {
empty_cols++;
continue;
}
var s = spans[i][j];
var rspan = (( s[0] && s[0] > 1 ) ? ' colspan="'+s[0]+'" ' : "");
if (s[1] && s[1] > 1){
rspan+=' rowspan="'+s[1]+'" ';
empty_cols = -1;
}
var val = "";
for (var k=0; k<row.cells.length; k++){
if (row.cells[k]._cellIndexS==j) {
if (row.cells[k].getElementsByTagName("SELECT").length)
val="";
else
val = _isIE?row.cells[k].innerText:row.cells[k].textContent;
val=val.replace(/[ \n\r\t\xA0]+/," ");
break;
}
}
if (!val || val==" ") empty_cols++;
cxml+="<column"+rspan+"><![CDATA["+val+"]]></column>";
};
if (empty_cols != grid._cCount)
xml+="\n<columns>"+cxml+"</columns>";
};
xml+="</head>\n";
xml+=xml_footer();
return xml;
};
you can then call the method in the following way:
myGrid.toPDF('http://localhost:8080/XML2PDF/generate', 'color','landscape');
As you could see, i am passing the extra parameter called ‘orientation’ to the toPDF method and then adding extra if statement to check for existing of this parameter then it will create an XML attribute which will get passed to the PDFXMLParser.java class which already checks for this attribute and decide if the page should be in landscape or portrait mode.
no extra modification is required to any other java class. The outcome should be a page rendered in a landscape mode.
As for the other, more important, issue which is getting my grid custom colors displayed, i am still not sure how to modify the code or if I should way until DHTMLX people release a proper version of the export to PDF functionality.
Let’s hope for the best 