Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file_content = base64_encode(file_get_contents("1.pdf"));
- ?>
- <!DOCTYPE>
- <html>
- <head>
- <title>Download PDF </title>
- </head>
- <body>
- <div>Hello World!</div>
- <input type="button" onclick="download()" value="download"/>
- <script>
- function download() {
- var str = "<?php echo $file_content;?>";
- var a = document.createElement("a");
- document.body.appendChild(a);
- a.style = "display: none";
- var data = window.atob(str);
- var blob = new Blob([data], {type: "application/pdf"});
- var url = window.URL.createObjectURL(blob);
- a.href = url;
- a.download = "download.pdf";
- a.click();
- window.URL.revokeObjectURL(url);
- }
- </script>
- </body>
- </html>
- var link = document.createElement('a');
- link.href = url;
- link.download = 'file.pdf';
- link.dispatchEvent(new MouseEvent('click'));
- $http.post('/postmethod',{params}, {responseType: 'arraybuffer'})
- .success(function (data) {
- var file = new Blob([data], {type: 'application/pdf'});
- var fileURL = URL.createObjectURL(file);
- window.open(fileURL);
- });
- function download() {
- var a = document.createElement("a");
- a.style = "display: none";
- a.href = "data:application/pdf;base64,<?= $file_content ?>";
- a.download = "download.pdf";
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement