<%@ language=jscript %>
<script SRC="collinsPdf.js" language="JavaScript" RUNAT="Server"></script>
<script SRC="collinsHtml.js" language="JavaScript" RUNAT="Server"></script>
<script SRC="collinsPdf.vb" language="VBScript" RUNAT="Server"></script>
<%
var cdoBasic = 1;
var cdoContentDisposition = "urn:schemas:mailheader:content-disposition";
//--------------- create a pdf
file in a scratch folder (must be writable) ---------------
html = new html$();
html.parse("<pdf margins=2 watermark='Sample' drawMargin=true
title='Hello World'>A Sample Static Graphic Object<br><graphic WIDTH=300
HEIGHT=300 BORDER=0 clip=true range='0,0,100,100'>Image
0,0,100,100,small_picture.jpg,0,{A};Text 20,75,0,Hello
World,,12,,;</graphic>");
pdf = new pdf$();
html.writeToPdf(pdf);
Temp = 1 * new Date();
filename = server.MapPath('./scratch/' + Temp + '.pdf');
pdf.writeToFile(filename);
//------------- email pdf file
---------------
to = "someone@somewhere.com";
mail = new ActiveXObject( "CDO.Message" );
mail.From = "me@somewhere.com";
mail.To = to;
mail.Subject = "Test PDF File"
mail.TextBody = "This is your PDF file"
mail.addAttachment(filename);
//------------- this stuff may not
be necessary on your server ---------
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")
= false;
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")
= 2;
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")
= cdoBasic;
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= 'somebody@mysite.com;
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= 'mypassword';
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "mail.server.com";
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25;
mail.Configuration.Fields.Update();
//----------------Rename the
attached file -----------------------
pdfname = 'test.pdf';
fields = mail.attachments(1).Fields
fields.Item(cdoContentDisposition) = "attachment;filename=" + pdfname;
fields.Update();
mail.Send();
//----------------- delete pdf
file -----------------------
fs = new ActiveXObject("Scripting.FileSystemObject");
fs.DeleteFile(filename, true);
Response.Write('PDF File has Been Emailed to ' + to);
%>
I am trying to use
the CollinsHTML and CollinsPDF to create a PDF document from some HTML
on the page. I am trying to use the sendToServer functions as I need to
also support firefox. However, when I try to run it I am always getting
an error: Automation server cannot
create object
ActiveXObject("ADODB.Stream");
I only support Internet Explorer. Firefox is a web browser that does not
permit read/writing to the client disk. If you are trying to add an
image to the PDF file then the system will read the file using the ADODB
activeX object. I am looking into the PDF option to include images as
external web references (http://mysite.org/images/house.gif). This
option seems to require an Adobe plug-in to view the PDF files so it may
not be very beneficial.
If
you are trying to support all web browsers, I recommend moving the PDF
generation to an ASP (or ASP.NET) server. .
If
you do not add an image to the PDF file created on the client side, then
it should be possible to use the sendToServer from Firefox, since there
is no file I/O involved. The only reasons that I would use the client
side generation of PDF files is, first; for testing, makes debugging
easier if client side only, second; the customer is Microsoft based and
there is a technical reason to do so.
I'm trying your CollinsPDF.js and CollinsHTML.js in Mozilla Firefox, client side, and get errors. How can I solve this problem?
Firefox does not allow client read/write of disk files. The
short answer is you cannot just use Firefox to generate PDF files. A
PDF file must be opened as a document, either as a file on the client side
(file://...), or as a document (http://...) on the server side.
- Use IE 6.x up (or compatible) browser which can write to the client disk
pdf.writeToFile('c:/temp/sample1.pdf');
window.open('file://c:/temp/sample1.pdf');
- Send the results to be stored on the server
pdf.sendToServer('sample1.pdf');
window.open('./sample1.pdf');
How many lines of code are in
CollinsPDF.js?
CollinsPDF.js and CollinsHTML.js each contain about
4200 lines of code about 4% are comments and blank lines.
Can I make modifications to the
CollinsPDF.js file?
Yes! you can make modification without changing
CollinsPDF.js
The code is copyrighted and there are certain restrictions on
publishing and reselling of the document and its technology that you will
need to become aware of, but the file is just a text file and is similar in
structure and coding conventions to all the samples found on this site.
I will warn you that any change you make will not be
supported under the License. Fixes, send them to me, I'll be glad to post
them. Enhancements I'll work with you if I can. the worst case might be that
I have to add an Event to the process to handle some really-really special
enhancement.
Will you add more graphic
functions to the PDF output?
Yes, I plan to add complete GIS capabilities into the PDF output. I will
first support the CG2 format to
PDF. ICMap can produce this graphic format off its
web pages, and therefore graphics (points, lines, arcs, circles, text,
polygons, symbols) from web user's input could go directly to the PDF file.
The PDF format also has some really nice shading and image capabilities.
What kind of Report Generator is
CollinsPDF?
First CollinsPDF does not read the database. It is
your job to read the database, sort the records, and then feed
CollinsPDF.js with a stream of records and keys. Or you
can read a text file and send it to
CollinsPDF.js to format into pages. Or you
can place individual text and graphics on the pages of the PDF.
The first case is illustrated in our online
report sample. The second case would
be to read a text file line by line and send each line to CollinsPDF to be
word wrapped and paginated, and you have the opportunity to place page
header and footers.
Can I replace my Crystal Reports
with CollinsPDF?
Technically Yes! I would have to see how many reports you have to give you a
time estimate. If you use a lot of sub-reports this will be a factor, I may
need to look at them to see what needs to be done. A single report can take
anywhere from a few minutes to a weeks to create, there is no magic wand to
convert the reports, they must be totally re-written.
This is what CollinsPDF was designed for, to generate
reports on a shared server and deliver them as PDF Files.
How long does it take to generate
a PDF files?
The process is extremely fast, our 13 page sample takes 1 or 2 seconds to
generate. I am shocked at the speed of JavaScript. My resource management
system CustomerCareSystem.com has probably 250,000
lines of JavaScript and it rivals in speed any workstation application I have
written, even when it is going over the web. The reason for this is that I
can load balance my application over multiple machines, so for the user it
is quick.
Is there anything I can't do by
using JavaScript?
No. I have heard there are limits in JavaScript but I have not found
any. With 30 year experience, I would say the same about COBOL, its just a
language.
You would not use JavaScript for a device drive, but this
rarely comes up. If you do have this need, then you simply perform the low
level I/O from an ActiveX object and attach it to your web page using
JavaScript. So; on you web Pages you only use JavaScript and that's all you
need.
Can I use your CollinsPDF.js with
VBScripts?
Yes, you can mix the 2 without any problems.
Can I insert images other than Jpeg into the PDF file?
Not at this time. Jpeg files are supported in the
PDF as binary blobs. I am looking into including another
graphic format to eliminate the blurred image that the jpeg format
inherently has. The format I pick will have transparency, and does not
blur, this will probably be PNG.
Should I create PDF files from the
client side?
There are reasons to generate PDF files from the client.
one reason is when you want to get information from any of the Microsoft's
Office Programs, such as MS-Word, Excel, or Outlook. These programs are
non-reentrant (single user) meaning they should do not be run from the
server side that have multiple users. From the
client side you can write scripts to extract their information and use
CollinsPDF to create PDF files, it is easy to extract this
information and is the preferred method.
Other reasons to use the client side is for development
and testing, and to reduce the load on the server for complex or time
consuming reports.
I have added a
sendToServer routine that allows the client to create the PDF
without using any local disk space and upload the result directly to
the server. This means that you will not need to worry about finding free
space on the disk to do scratch work, and it reduces the security concerns.
In effect the user would never know where the PDF was generated.
Is there a Limit on the size of a PDF file that I generate?
The CollinsPDF.js current implementation is memory resident,
with the exception of images, therefore you may run out of memory on VERY
large pdf files. I would try and stay below 100 pages on most reports. You
will simply run out of memory and the program will fail. Future releases
will most likely remove this limitation, and use a database or disk space to
hold intermediate results, thus drastically reducing the memory
requirements, then the limitation will be the physical limits of the PDF
file itself.
Why use PDF instead of HTML?
PDF are paginated and printable, so when delivering documents to a client you are assured
that he will be able to view and print the document as you have designed. Use PDF to mail to the client as a permanent
copy and store them on your server for future reference. When delivering quotes and rate sheets it is extremely important
that you and the client are looking at the same document. PDFs that I send to
the client are first store on the server as a permanent document and I email
him this copy, document that are generated from the database have "DRAFT" on
them and are never intended to be seen by the client. Reports from the
database could be HTML documents except with the 1 exception that page
breaks cannot be used, in a PDF it is designed as pages and therefore the
user can the see pages and select the
pages to print, with page header and footers.
Is there a limit on the number of
group header I can have in a report?
There is no limit.