PDA

View Full Version : Good and Nice JavaScripts



JavaScriptBank
09-09-2010, 08:55 PM
Helpful JavaScript for Web development

jsPDF: Generating your PDF Web Page Documents using JavaScript

<b>jsPDF</b> is an open-source JavaScript library (http://www.javascriptbank.com/javascript/) written by <i>James</i>, this tool allow us generate PDF web page documents in server-side and client-side by using nothing... detail (http://www.javascriptbank.com/jspdf-generating-pdf-web-page-documents-using-javascript.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)


http://www.javascriptbank.com/javascript.images/utility/jspdf-generating-pdf-web-page-documents-using-javascript.jpg (http://www.javascriptbank.com/javascript/utility/generator/jspdf-generating-pdf-web-page-documents-using-javascript/preview/en/)
Demo: JavaScript jsPDF: Generating your PDF Web Page Documents using JavaScript (http://www.javascriptbank.com/jspdf-generating-pdf-web-page-documents-using-javascript.html/en/)


How to setup

Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript

<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript" src="sprintf.js"></script>
<script type="text/javascript" src="jspdf.js"></script>

<script type="text/javascript">

function demo1() {
var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Output as Data URI
doc.output('datauri');
}

function demo2() {
var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');

// Output as Data URI
doc.output('datauri');
}

function demo3() {
var doc = new jsPDF();
doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.');

// Optional - set properties on the document
doc.setProperties({
title: 'Title',
subject: 'This is the subject',
author: 'James Hall',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'MEEE'
});

// Output as Data URI
doc.output('datauri');
}

function demo4() {
var name = prompt('What is your name?');
var multiplier = prompt('Enter a number:');
multiplier = parseInt(multiplier);

var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'Questions');
doc.setFontSize(16);
doc.text(20, 30, 'This belongs to: ' + name);

for(var i = 1; i <= 12; i ++) {
doc.text(20, 30 + (i * 10), i + ' x ' + multiplier + ' = ___');
}

doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'Answers');
doc.setFontSize(16);

for(var i = 1; i <= 12; i ++) {
doc.text(20, 30 + (i * 10), i + ' x ' + multiplier + ' = ' + (i * multiplier));
}
doc.output('datauri');

}

</script>

Step 2: Place HTML below in your BODY section
HTML

<h2>Simple Two-page Text Document</h2>
<pre>var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo1()">Run Code</a>

<h2>Different font sizes</h2>
<pre>var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'This is a title');

doc.setFontSize(16);
doc.text(20, 30, 'This is some normal sized text underneath.');

// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo2()">Run Code</a>


<h2>Adding metadata</h2>
<pre>var doc = new jsPDF();
doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.');

// Optional - set properties on the document
doc.setProperties({
title: 'Title',
subject: 'This is the subject',
author: 'James Hall',
keywords: 'generated, javascript, web 2.0, ajax',
creator: 'MEEE'
});

// Output as Data URI
doc.output('datauri');</pre>
<a href="javascript:demo3()">Run Code</a>


<h2>Example of user input</h2>
<pre>var name = prompt('What is your name?');
var multiplier = prompt('Enter a number:');
multiplier = parseInt(multiplier);

var doc = new jsPDF();
doc.setFontSize(22);
doc.text(20, 20, 'Questions');
doc.setFontSize(16);
doc.text(20, 30, 'This belongs to: ' + name);

for(var i = 1; i <= 12; i ++) {
doc.text(20, 30 + (i * 10), i + ' x ' + multiplier + ' = ___');
}

doc.addPage();
doc.setFontSize(22);
doc.text(20, 20, 'Answers');
doc.setFontSize(16);

for(var i = 1; i <= 12; i ++) {
doc.text(20, 30 + (i * 10), i + ' x ' + multiplier + ' = ' + (i * multiplier));
}
doc.output('datauri');</pre>
<a href="javascript:demo4()">Run Code</a>

Step 3: downloads
Files
base64.js (http://www.javascriptbank.com/javascript/utility/jsPDF Generating your PDF Documents using JavaScript/base64.js)
jspdf.js (http://www.javascriptbank.com/javascript/utility/jsPDF Generating your PDF Documents using JavaScript/jspdf.js)
sprintf.js (http://www.javascriptbank.com/javascript/utility/jsPDF Generating your PDF Documents using JavaScript/sprintf.js)







JavaScript Countdown Timer (http://www.javascriptbank.com/javascript-countdown-timer.html/en/) - JavaScript Web based Music Player (http://www.javascriptbank.com/web-based-music-player.html) - Free JavaScript Codes (http://www.javascriptbank.com/)


The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.

Stephany297
09-10-2010, 06:05 AM
Make a message box when it is open.
<!-- this script got from www.javascriptfreecode.com coded by: Krishna Eydat-->
<html>
<head>
<script language="javascript" type="text/javascript">
alert("Welcome to my site")
</script>
</head>
</html>
<font face="Tahoma"><a target="_blank" href="http://www.javascriptfreecode.com/"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font>
_______________________________

Malaysia Flights (http://www.malaysia.com/flights.html)
Kuala Lumpur Accommodation (http://www.malaysia.com/hotels.html)

brainpulse
09-23-2010, 07:08 AM
really interesting java scripts .


thanks