test_insert_page.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!doctype html>
  2. <!--
  3. /**
  4. * jsPDF Insert Page PlugIn
  5. * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
  6. *
  7. * Licensed under the MIT License.
  8. * http://opensource.org/licenses/mit-license
  9. */
  10. -->
  11. <html>
  12. <head>
  13. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  14. <title>Insert/Move/Delete Page Test</title>
  15. <script type="text/javascript" src="../jspdf.js"></script>
  16. <script type="text/javascript" src="test_harness.js"></script>
  17. <script>
  18. pdf_test_harness.onload = function(harness) {
  19. var pdf = new jsPDF('p', 'pt', 'letter');
  20. var textHeight = 16;
  21. var y = 0;
  22. var pad = 5;
  23. var context;
  24. pdf.text("Page 1", 20, y + textHeight);
  25. y += textHeight + pad;
  26. context = pdf.internal.getPageInfo(1).pageContext;
  27. context.data = 'this is page 1';
  28. pdf.addPage();
  29. y=0;
  30. pdf.text("Page 2", 20, y + textHeight);
  31. y += textHeight + pad;
  32. context = pdf.internal.getPageInfo(2).pageContext;
  33. context.data = 'this is page 2';
  34. pdf.insertPage(1);
  35. y=0;
  36. pdf.text("Inserted Page", 20, y + textHeight);
  37. y += textHeight + pad;
  38. context = pdf.internal.getCurrentPageInfo().pageContext;
  39. context.data = 'this is page inserted';
  40. pdf.movePage(3, 2);
  41. pdf.addPage();
  42. pdf.text("Page Delete Me", 20, y + textHeight);
  43. y += textHeight + pad;
  44. pdf.deletePage(pdf.currentPage);
  45. pdf.insertPage(1);
  46. y=0;
  47. pdf.text("Testing Insert Page", 20, y + textHeight);
  48. y += textHeight + pad;
  49. pdf.text("Order should be [inserted page] [page 2] [page 1]", 20, y + textHeight);
  50. y += textHeight + pad;
  51. pdf.text("[page 4] should have been deleted", 20, y + textHeight);
  52. y += textHeight + pad;
  53. pdf.internal.getCurrentPageInfo().pageContext.data = 'This is the title page';
  54. // verify context was moved
  55. pdf.addPage();
  56. for (var i=1; i<=4; i++){
  57. context = pdf.internal.getPageInfo(i).pageContext;
  58. pdf.text("Page " + i, 20, i*30);
  59. pdf.text("context " + context.data, 30, i*30 + 10);
  60. }
  61. return pdf;
  62. }
  63. </script>
  64. </head>
  65. <body style='background-color: silver; margin: 0;'>
  66. </body>
  67. </html>