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

The PDF creator handles many of the standard reporting functions, most notably is the handling of table structures, which is accomplished by use of a ruler.  A ruler is a list of values that define columns and how they should treat the text within the cells.  Text within a cell can be left, right, center or period justified. Text that exceeds the cell width can be truncated, truncated with 3 dots (...), or word wrapped. You may use as many rulers as required to format the text.  Text can be placed into the document without a ruler, in this case the text will be word warped and paginated, and as text is added it will be positioned to the end of the previous text allowing font characteristics to be adjusted on a character by character basis.


Client Side - Using Header / Footer Callback Example:

<html><head><title>Header / Footer pdf</title></head>
<script src="CollinsPdf.js" language="javascript"></script>
<script>
//===========================================================
//			createPdf
//===========================================================
function createPdf()
{
	pdf = new pdf$('', pageheader, pagefooter);
	
	pdf.setFontSize(24);
	pdf.addText('Hello World');

	pdf.writeToFile('c:/temp/sample_header.pdf');
}
//===========================================================
//			pageheader
//===========================================================
function pageheader(page,totalPages,pdf)
{
	pdf.lineBreak();	
	pdf.setFontSize(14);
	pdf.centerText('Collins Software');
}
//===========================================================
//			pagefooter
//===========================================================
function pagefooter(page,totalPages,pdf)
{
	pdf.setFontSize(10);
	pdf.centerText('Page: ' + page + ' of ' + totalPages);
}

</script>
<body>
<input type=button value="Create PDF" onClick=createPdf()>
</body>
</html>			



Client Side - Using Ruler Example

A Ruler defines left, right margins and 0 or more tab positions. This example sets 3 tab positions first tab 4" for the part number, second tab at 5" right justified for Quantity, and the third tab at 6" justified on the decimal place (Period) for the price.
<html><head><title>PDF Sample Ruler</title></head>
<script src="scripts/CollinsPdf.js" language="javascript"></script>
<script>
//===========================================================
//			createPdf
//===========================================================
function createPdf()
{
	pdf = new pdf$();
	pdf.setRuler('1,4,R5,P6,7.5');

//---------- Column Headings ----------
	values = new Array();
	values[0] = 'Name';
	values[1] = 'Part';
	values[2] = 'Qnty';
	values[3] = 'Price';
	pdf.addHeader(values};

//---------- Details ----------

	values[0] = 'Power switch (mini SPDT* toggle)';
	values[1] = 7313;
	values[2] = 3;
	values[3] = '$150.50';
	pdf.addRow(values);

	values[0] = 'DIP-8 IC sockets, gold contacts';
	values[1] = 'AE5432';
	values[2] = 12;
	values[3] = '$1,234.75';
	pdf.addRow(values);

	pdf.writeToFile('c:/temp/sample_ruler.pdf');
}
</script>
<body>
<input type=button value="Create PDF" onClick=createPdf()>
</body>
</html>



Client Side - Full ADO Example PDF Report:

<html><head><title>PDF Sample ADO Report</title></head>
<script src="scripts/CollinsPdf.js" language="javascript"></script>
<script>
//===========================================================
//			createPdf
//===========================================================
function createPdf()
{
var i,line,cnn,rs;

	pdf = new pdf$('DRAFT',onPageheader,onPagefooter,onPagebreak,false);
	pdf.setRuler('R0.5,1.25W,4,5.3,6,8');
	pdf.setRulerAlign('middle');
	pdf.setBorderWidth(1);

	onPagebreak();

//---------- Details ----------

	line = 0
	cnn = new ActiveXObject('ADODB.Connection');
	cnn.open("provider= microsoft.jet.oledb.4.0; data source=pdf_sample.mdb");
	rs = new ActiveXObject('ADODB.recordset');
	rs.Open('select * from data order by st,city,sortname' ,cnn,2,3);
	rs.MoveFirst();

	values = new Array();
	while (! rs.EOF)
	{
		line = line + 1;
		values[0] = line;
		values[1] = rs('fullname').Value;
		values[2] = rs('city').Value;
		values[3] = rs('st').Value;
		values[4] = rs('controlName').Value; 
		pdf.addReportDetail(values);
		if (line > 200) break;
		rs.MoveNext();
	}

	pdf.writeToFile('c:/temp/sample_ado.pdf');
}
//=================================================================
// 			onPageheader
//=================================================================
function onPageheader(page,totalPages.pdf)
{
	pdf.setFontSize(24);
	pdf.setFontColor('darkRed');
	pdf.centerText('Collins Software');
	pdf.lineBreak();
	pdf.setFontSize(12);
	pdf.centerText('Sample ADO Report');
}
//=================================================================
// 			onPagefooter
//=================================================================
function onPagefooter(page,totalPages.pdf)
{
	pdf.setFontSize(8);
	pdf.setFontColor('silver');
	pdf.addText(' http://collinssoftware.com');

	pdf.setFontSize(10);
	pdf.setFontColor('black');
	pdf.centerText('Page: ' + page + ' of ' + totalPages);
}
//=================================================================
//			 onPagebreak
//=================================================================
function onPagebreak()
{
	values = new Array();
	values[0] = 'Name';
	values[1] = 'City';
	values[2] = 'State';
	values[3] = 'Type';	
	pdf.addHeader(values);
}
</script>
<body>
<input type=button value="Create PDF" onClick=createPdf()>
</body>
</html>



Using Graphics and Jpeg Images to create Letter Head:
//==================================================================
// 			createPdf
//==================================================================
function createPdf()
{
	pdf = new pdf$();

	pdf.setGraphicColor('HoneyDew');
	pdf.drawRectangle(0,0,8.5,1.2);
	pdf.setGraphicColor('black');
	pdf.placeImage(0.5,0,'ShoppingCart.jpg',1.2,0,0);

	pdf.setFontSize(24);
	pdf.setBold(true);
	pdf.setItalic(true);
	pdf.placeText(2,0.5,'Collins Software');

	pdf.setBold(false);
	pdf.setItalic(false);
	pdf.setFontSize(48);
	pdf.placeText(2,1.1,'I N V O I C E');
	pdf.setLineWeight(3);
	pdf.drawLine(0,1.2,8.5,1.2);

	pdf.setFontSize(8);
	pdf.placeText(6.2,0.2,'Send payment to:');
	pdf.placeText(6.5,0.35,'Collins Software');
	pdf.placeText(6.5,0.5,'7710 Janak Drive');
	pdf.placeText(6.5,0.65,'Houston, Texas 77055');

	pdf.setBold(true);
	pdf.placeText(6.5,1.0,'(713) 682-1556');

	pdf.writeToFile('c:/temp/sample_3.pdf');
}
</script>



Add Hyperlinks:
	
	pdf = new pdf$();
	pdf.addText('Welcome to the world of ');
	pdf.addText('Collins Software','http://CollinsSoftware.com');

 

Add BookMarks:
create a multi-level document outline to assist navigation.


	parent = pdf.addOutline(null,'Chapter 1',ypos);
	child = pdf.addOutline(parent,'References',ypos);
	
	pdf.addOutline(child,'PDF Examples',ypos);