|
| 1 | +<!doctype html> |
| 2 | +<!-- |
| 3 | +/** |
| 4 | + * jsPDF Insert Page PlugIn |
| 5 | + * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) [email protected] |
| 6 | + * |
| 7 | + * Licensed under the MIT License. |
| 8 | + * http://opensource.org/licenses/mit-license |
| 9 | + */ |
| 10 | +--> |
| 11 | + |
| 12 | +<html> |
| 13 | +<head> |
| 14 | +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| 15 | + |
| 16 | +<title>Insert/Move/Delete Page Test</title> |
| 17 | + |
| 18 | +<script type="text/javascript" src="../jspdf.js"></script> |
| 19 | + |
| 20 | +<script> |
| 21 | + window.onload = function() { |
| 22 | + |
| 23 | + var pdf = new jsPDF('p', 'pt', 'letter'); |
| 24 | + |
| 25 | + var textHeight = 16; |
| 26 | + var y = 0; |
| 27 | + var pad = 5; |
| 28 | + |
| 29 | + pdf.text("Page 1", 20, y + textHeight); |
| 30 | + y += textHeight + pad; |
| 31 | + |
| 32 | + pdf.addPage(); |
| 33 | + y=0; |
| 34 | + pdf.text("Page 2", 20, y + textHeight); |
| 35 | + y += textHeight + pad; |
| 36 | + |
| 37 | + pdf.insertPage(1); |
| 38 | + y=0; |
| 39 | + pdf.text("Inserted Page", 20, y + textHeight); |
| 40 | + y += textHeight + pad; |
| 41 | + |
| 42 | + pdf.movePage(3, 2); |
| 43 | + |
| 44 | + pdf.addPage(); |
| 45 | + pdf.text("Page Delete Me", 20, y + textHeight); |
| 46 | + y += textHeight + pad; |
| 47 | + |
| 48 | + pdf.deletePage(pdf.currentPage); |
| 49 | + |
| 50 | + pdf.insertPage(1); |
| 51 | + y=0; |
| 52 | + pdf.text("Testing Insert Page", 20, y + textHeight); |
| 53 | + y += textHeight + pad; |
| 54 | + pdf.text("Order should be [inserted page] [page 2] [page 1]", 20, y + textHeight); |
| 55 | + y += textHeight + pad; |
| 56 | + pdf.text("[page 4] should have been deleted", 20, y + textHeight); |
| 57 | + y += textHeight + pad; |
| 58 | + |
| 59 | +/////////////////////////////////////////////////////////////////////////////// |
| 60 | +// end testing |
| 61 | +/////////////////////////////////////////////////////////////////////////////// |
| 62 | + |
| 63 | + // generate either the pdf or source code |
| 64 | + if (getParameterByName('src') != 'true'){ |
| 65 | + var frame = document.getElementById('pdfframe'); |
| 66 | + frame.src = pdf.output('datauristring'); |
| 67 | + } |
| 68 | + else{ |
| 69 | + var content = document.getElementById('sourcecode'); |
| 70 | + var raw = pdf.output(); |
| 71 | + raw = escapeHtml(raw); |
| 72 | + content.innerHTML = raw; |
| 73 | + } |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | + var entityMap = { |
| 78 | + "&": "&", |
| 79 | + "<": "<", |
| 80 | + ">": ">", |
| 81 | + '"': '"', |
| 82 | + "'": ''', |
| 83 | + "/": '/' |
| 84 | + }; |
| 85 | + |
| 86 | + function escapeHtml(string) { |
| 87 | + return String(string).replace(/[&<>"'\/]/g, function (s) { |
| 88 | + return entityMap[s]; |
| 89 | + }); |
| 90 | + } |
| 91 | + |
| 92 | + function getParameterByName(name) { |
| 93 | + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); |
| 94 | + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), |
| 95 | + results = regex.exec(location.search); |
| 96 | + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); |
| 97 | + } |
| 98 | + |
| 99 | +</script> |
| 100 | + |
| 101 | +</head> |
| 102 | + |
| 103 | +<body style='background-color: silver; margin: 0;'> |
| 104 | + <pre id='sourcecode'></pre> |
| 105 | + <iframe id='pdfframe' style='width: 100%; height: 100%; position: absolute'></iframe> |
| 106 | +</body> |
| 107 | +</html> |
0 commit comments