|
View A Sample
PDF Report
(13 Pages) This code generates the PDF file only using JavaScript. The CollinsPDF.js is a JavaScript object than handles all the reporting and PDF file creation logic without the need for any other library or software. This means that this code runs both at the server and on the client side. This code illustrates the basic functions of the CollinsPDF.js Page 7 of the report highlight some of the conditions handling by CollinsPDF.js;
Program Logic:
Element of the PDF files used in this report are:
<html><head><title>CollinsPDF Sample Report</title></head>
<script src="CollinsPdf.js" language="javascript"></script>
<script>
//===========================================================
// createPdf
//===========================================================
function createPdf()
{
var i,line,cnn,rs,keys,text;
pdf = new pdf$('SAMPLE',onPageheader,onPagefooter,null,false);
pdf.createReportGroup(0,0,null,null,true,false,true,false);
pdf.createReportGroup(1,0,onCityHeader,null,true,false,false,false);
pdf.setRuler('R0.5,1.25W,4.5,6,8');
pdf.setRulerAlign('middle');
pdf.setBorderWidth(1);
keys = new Array();
values = new Array();
//---------- Details ----------
line = 0
cnn = new ActiveXObject('ADODB.Connection');
cnn.open("provider= microsoft.jet.oledb.4.0; data source=./Sample_ado.mdb");
rs = new ActiveXObject('ADODB.recordset');
rs.Open('select * from data order by st,city,sortname' ,cnn,2,3);
rs.MoveFirst();
while (! rs.EOF)
{
line = line + 1;
values[0] = line;
values[1] = rs('fullname').Value;
values[2] = rs('type').Value;
values[3] = rs('class').Value;
keys[0] = rs('st').Value;
keys[1] = rs('city').Value;
pdf.addReportDetail(values,keys);
if (line > 300) break;
rs.MoveNext();
}
pdf.writeToFile('c:/temp/sample_report.pdf');
}
//=================================================================
// onCityheader
//=================================================================
function onCityHeader(pdf,index,keys,count)
{
var state,text;
state = 'unknown';
if (keys[0] == 'AK') state = 'Alaska';
if (keys[0] == 'AR') state = 'Arkansas';
if (keys[0] == 'AL') state = 'Alabama';
if (keys[0] == 'AZ') state = 'Arizona';
if (keys[0] == 'CA') state = 'California';
text = state + ' ' + keys[1];
pdf.setFontColor('SlateBlue');
pdf.addText(text);
pdf.lineBreak();
pdf.setFontColor('Black');
}
//=================================================================
// onPageheader
//=================================================================
function onPageheader(page,totalPages,pdf)
{
pdf.setFontSize(24);
pdf.setFontColor('Black');
pdf.setGraphicColor('Moccasin');
pdf.drawRectangle(0,0,8.5,0.7);
pdf.placeImage(1.0,0.03,'workers.jpg',0.65,0,0);
pdf.centerText('Collins Software','http://CollinsSoftware.com');
pdf.lineBreak();
pdf.setFontSize(12);
pdf.centerText('Sample Report Created using CollinsPDF.js');
}
//=================================================================
// onPagefooter
//=================================================================
function onPagefooter(page,totalPages,pdf)
{
pdf.setFontSize(8);
pdf.setFontColor('Tomato');
pdf.setGraphicColor('Moccasin');
pdf.drawRectangle(0,10.3,8.5,11);
pdf.addText(' ')
pdf.addText('CollinsSoftware.com','http://collinssoftware.com');
pdf.setFontSize(10);
pdf.setFontColor('black');
pdf.centerText('Page: ' + page + ' of ' + totalPages);
}
</script>
<body>
<input type=button value="Create sample_report.pdf" onClick=createPdf()><br><br>
Copyright © 2010, Clifford L. Collins<br>
All rights are reserved
</body>
</html>
|
|
|