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

Making Modification to CollinsPDF.js
Change / Add / Replace Functions

You do not want to modify the CollinsPD F.js file directly!!!  It will make hard for you to use any updated to the program...

JavaScript is Great... you can make modifications to the original program without having to change the file. The reason for this is that JavaScript uses the LAST read routine. This means that if you want to change CollinsPDF.js you can do so, simple copy out the routines in question, modify them, and place them after the CollinsPDF.js source. You can also add functions to CollinsPDF.js simply by declaring them. Finally you can change the way the program is executed by intercepting the routines, see below:

This example show how to modify a function in CollinsPDF.js, it sets the font color to RED no matter what...

<html><head><title>CollinsPDF Sample_Modify_Add</title>
<script src="CollinsPdf.js" language="javascript"></script>
<script language=javascript>
//****************************************************************************
// 			pdf$setFontColor
// My Set Font Color Routine, copied out of CollinsPdf.js and modified
//*****************************************************************************
function pdf$setFontColor(value)
{
	this.fontColor = 0xFF0000;
}
//===========================================================================
// 			createPdf
//===========================================================================
function createPdf()
{
	pdf = new pdf$();

	pdf.setFontSize(36);
	pdf.setFontColor('black');
	pdf.centerText('Hello World');
	pdf.writeToFile('c:/temp/sample_modify.pdf');
}
</script></head><body>
<input type=button value="Create PDF File" onClick=createPdf()><br>
Copyright © 2008, Clifford L. Collins
All rights are reserved
</body></html>



This example show how to add Functions to CollinsPDF.js. This example add a new function addFile to the pdf object. The addFile will open a text file and place into the PDF.
 
<html><head><title>CollinsPDF Sample_Modify_New</title>
<script src="CollinsPdf.js" language="javascript"></script>
<script language=javascript>
//****************************************************************************
// 			my_pdf$addFile
//*****************************************************************************
function my_pdf$addFile(filename)
{
	var list,i,fs,f,text;

	fs = new ActiveXObject("Scripting.FileSystemObject");
	f = fs.OpenTextFile('c:/temp/' + filename);
	text = f.ReadAll();
	f.Close();

	list = text.split('\r\n');
	for (i=0; i < list.length; ++i) 
	{
		this.addText(list[i]);
		this.lineBreak();
	}
}
//===========================================================================
// 			createPdf
//===========================================================================
function createPdf()
{
	pdf = new pdf$();
	pdf.addFile = my_pdf$addFile; // declare your function

	pdf.setFontSize(12);
	pdf.setFontColor('black');
	pdf.addFile('sample.txt');
	pdf.writeToFile('c:/temp/sample_modify_add.pdf');
}
</script>
<body bgcolor=#A8A8FF>
<input type=button value="Create PDF File" onClick=createPdf()><br>
</body></html>


This example show show to change only certain behaviors of the process. This example changes the logic of the setFontColor routine by replace the original routine with a new one, and renaming the original routine so it can be used. In this case the setFontColor routine will function as normal except if the color is Black (0) then it will be changed to Red (0xFF0000)

<html><head><title>CollinsPDF Sample_Modify_Add</title>
<script src="CollinsPdf.js" language="javascript"></script>
<script language=javascript>
//****************************************************************************
// 			my$setFontColor
//  routine only changes the color black to red, otherwise leave it alone
//*****************************************************************************
function my$setFontColor(value)
{
	this.setFontColor_original(value);
	if (this.fontColor == 0) this.fontColor = 0xFF0000;	// black --> red
}
//===========================================================================
// 			createPdf
//===========================================================================
function createPdf()
{
	pdf = new pdf$();
	pdf.setFontColor 		= my$setFontColor;		// use my setFontColor;
	pdf.setFontColor_original 	= pdf$setFontColor;	// link to the original setFontColor

	pdf.setFontSize(36);
	pdf.setFontColor('black');
	pdf.centerText('Hello World');
	pdf.setFontColor('blue');
	pdf.lineBreak();
	pdf.centerText('Hello World');
	pdf.writeToFile('c:/temp/sample_modify_change.pdf');
}
</script></head><body>
<input type=button value="Create PDF File" onClick=createPdf()><br>
Copyright © 2008, Clifford L. Collins
All rights are reserved
</body></html>