简体   繁体   中英

pdf file size javascript or html5

Is there a way I can get the file size of a PDF without clicking on a button from an input box. Basically I have a row of 5 links to pdf files, and I want to append the filesize of each pdf on to the end of the link:

<a href="www.pdf.com/pdf">PDF Name - 4MB</a>
<a href="www.pdf.com/pdf">PDF Name - 4MB</a>

Thanks

Richard

        // File size counter function 
    function readablizeFilesize(bytes) {
    var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
    var e = Math.floor(Math.log(bytes)/Math.log(1024));
    return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
    }
    var length = request.getResponseHeader("Content-Length");
    if (!isNaN(parseInt(length))) {
    var fileSize = readablizeFilesize(length);
    var anchor = '<a href="www.pdf.com/pdf">PDF Name - ' + fileSize + '</a>'
    console.log(anchor);

    }
Plese Try with this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM