templates/base64-to-pdf.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}
  3. ToBase64.dev - Convert base64 to PDF, Encode base64 to PDF
  4. {% endblock %}
  5. {% block h1 %}Convert your base64 to a PDF{% endblock %}
  6. {% block body %}
  7. <div class="row" style="height: 60%;">
  8. <div class="padding col-5">
  9. <form method="post" action="" class="form" style="height: 100%">
  10. <textarea class="form-control" id="input3" name="input3" placeholder="Type (or paste) here..." spellcheck="false" style="width: 100%;height: 100%;"></textarea>
  11. </form>
  12. </div>
  13. <div class="col-2 d-flex flex-column">
  14. <div class="padding row" style="margin-top:auto;margin-bottom:auto;">
  15. <button type="button" onclick="toPdf()" class="col-12 btn btn-info"><i class="fas fa-long-arrow-alt-right"></i></button>
  16. </div>
  17. </div>
  18. <div class="padding col-5 d-flex flex-column">
  19. <div style="height: 85%">
  20. <div id="output3" style="
  21. border-left-width: 5px;
  22. border-top-width: 5px;
  23. border-right-width: 5px;
  24. border-bottom-width: 5px;
  25. border-color: #17a2b8;
  26. border-style: solid;
  27. height: 100%;
  28. width: 100%;
  29. ">
  30. <object id="pdfb64" data="" type="application/pdf" width="100%" height="100%">
  31. </object>
  32. </div>
  33. </div>
  34. <button id="download" type="button" class="btn btn-info" onclick="download()" style="margin-top:auto;">Download!</button>
  35. </div>
  36. </div>
  37. <script type="text/javascript">
  38. // Add the following code if you want the name of the file appear on select
  39. $(".custom-file-input").on("change", function() {
  40. var fileName = $(this).val().split("\\").pop();
  41. $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
  42. });
  43. function copyToClipboard() {
  44. var copyText = document.getElementById("output1");
  45. copyText.select();
  46. document.execCommand("copy");
  47. }
  48. function download() {
  49. var url = document.getElementById('pdfb64').data;
  50. var link = document.createElement('a');
  51. link.href = url;
  52. link.download = 'document.pdf';
  53. document.body.appendChild(link);
  54. link.click();
  55. document.body.removeChild(link);
  56. }
  57. function toPdf() {
  58. var string = document.getElementById('input3').value;
  59. var image = "data:application/pdf;base64," + string;
  60. document.getElementById('pdfb64').data = image;
  61. document.getElementById('download').disabled = false;
  62. }
  63. function totext() {
  64. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  65. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  66. r = e.charCodeAt(f++);
  67. i = e.charCodeAt(f++);
  68. s = n >> 2;
  69. o = (n & 3) << 4 | r >> 4;
  70. u = (r & 15) << 2 | i >> 6;
  71. a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0;
  72. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  73. o = this._keyStr.indexOf(e.charAt(f++));
  74. u = this._keyStr.indexOf(e.charAt(f++));
  75. a = this._keyStr.indexOf(e.charAt(f++));
  76. n = s << 2 | o >> 4;
  77. r = (o & 15) << 4 | u >> 2;
  78. i = (u & 3) << 6 | a;
  79. t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192);
  80. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  81. t += String.fromCharCode(r >> 6 & 63 | 128);
  82. t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r);
  83. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  84. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  85. n += 2 } else { c2 = e.charCodeAt(n + 1);
  86. c3 = e.charCodeAt(n + 2);
  87. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  88. n += 3 } } return t } }
  89. // Define the string
  90. var string = document.getElementById('input4').value;
  91. // Encode the String
  92. var decodedString = Base64.decode(string);
  93. document.getElementById('output4').value = decodedString;
  94. }
  95. function tobase64() {
  96. var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0;
  97. e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++);
  98. r = e.charCodeAt(f++);
  99. i = e.charCodeAt(f++);
  100. s = n >> 2;
  101. o = (n & 3) << 4 | r >> 4;
  102. u = (r & 15) << 2 | i >> 6;
  103. a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0;
  104. e = e.replace(/\\+\\+[++^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++));
  105. o = this._keyStr.indexOf(e.charAt(f++));
  106. u = this._keyStr.indexOf(e.charAt(f++));
  107. a = this._keyStr.indexOf(e.charAt(f++));
  108. n = s << 2 | o >> 4;
  109. r = (o & 15) << 4 | u >> 2;
  110. i = (u & 3) << 6 | a;
  111. t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192);
  112. t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224);
  113. t += String.fromCharCode(r >> 6 & 63 | 128);
  114. t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r);
  115. n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1);
  116. t += String.fromCharCode((r & 31) << 6 | c2 & 63);
  117. n += 2 } else { c2 = e.charCodeAt(n + 1);
  118. c3 = e.charCodeAt(n + 2);
  119. t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
  120. n += 3 } } return t } }
  121. // Define the string
  122. var string = document.getElementById('input2').value;
  123. // Encode the String
  124. var encodedString = Base64.encode(string);
  125. document.getElementById('output2').value = encodedString;
  126. }
  127. </script>
  128. <script>
  129. function handleFileSelect(evt) {
  130. document.getElementById("loading").style.display = "";
  131. var files = evt.target.files; // FileList object
  132. // Loop through the FileList and render image files as thumbnails.
  133. for (var i = 0, f; f = files[i]; i++) {
  134. // Only process image files.
  135. if (!f.type.match('image.*')) {
  136. continue;
  137. }
  138. var reader = new FileReader();
  139. // Closure to capture the file information.
  140. reader.onload = (function(theFile) {
  141. return function(e) {
  142. // Render thumbnail.
  143. document.getElementById('imageb64').src = e.target.result;
  144. document.getElementById("output3").value = "url('" + e.target.result + "')";
  145. document.getElementById("output2").value = e.target.result;
  146. document.getElementById("output1").value = e.target.result.split(',')[1];
  147. imageB64 = e.target.result;
  148. document.getElementById("loading").style.display = "none";
  149. };
  150. })(f);
  151. // Read in the image file as a data URL.
  152. reader.readAsDataURL(f);
  153. }
  154. }
  155. //document.getElementById('files').addEventListener('change', handleFileSelect, false);
  156. </script>
  157. {% endblock %}