base-64-PDF
by velo_ninja
HTML
<!DOCTYPE html>
<html>
<head>
<title>PDF to Base64</title>
</head>
<body>
<input type="file" id="pdfFile" accept=".pdf">
<button onclick="convertToBase64()">Convert to Base64</button>
<div id="output"></div>
<script>
function convertToBase64() {
var input = document.getElementById('pdfFile');
var file = input.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function(e) {
var base64String = e.target.result.split(',')[1]; // Get rid of data URL prefix
document.getElementById('output').innerHTML = base64String;
// You can now transmit `base64String` over the network
// For example, using AJAX to send it to the server
};
reader.readAsDataURL(file);
} else {
alert('Please select a PDF file.');
}
}
</script>
</body>
</html>