HOME

Products
The Arc
HTML to PDF

Free CollinsPDF.js
Free CollinsHTML.js
Free GIS

(on-line service)
CustomerCareSystem
Scripts
 

CollinsPDF FAQ More Examples How to Modify Reference Guide Sample Report

 

View A Sample PDF Report  (13 Pages)  

view code used to generate the report

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;

  • A Page Break occurred at the top when the State changed from Arkansas to Arizona (group 1),
  • A Page Break occurred when the City of Phoenix could not fit on page 7, (group 2)
  • Page numbering, a small but important part of any document

Program Logic:

  • Create an new pdf object
  • Create 2 Report Groups
    • Group 1 for State, no header or footer, keep together, and Page Break on change
    • Group 2 for City, a header that print the city and State name, keep together on same page
  • Define a Table, using a ruler to define the Left/Right margins and Column Settings. Set Word Wrap on the University Name, truncate the other columns
  • Set Column Vertical Alignment to "middle"
  • Set to draw border around columns
  • Open an Access Database
  • Read Database using SQL
  • Output the records to the PDF object
  • Write to file

Element of the PDF files used in this report are:

  • Watermarks
  • Jpeg images
  • Hyperlinks
  • Graphic rectangle
<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>