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...
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)