Data URI Hash Parameters (Hide PDF toolbar for data URI)

前端 未结 4 2096
既然无缘
既然无缘 2021-02-15 04:00

I have a PDF base64 encode data URI.

eg:

return 

        
      
      
      
4条回答
  •  后悔当初
    2021-02-15 04:51

    Like kolin said there is no way to directly send in query strings with a data URI. However, you can switch the data URI into a blob URL and pass the parameters in there.

    Just take your base64 data and convert it into a pdf blob like so:

    function b64toBlob(b64Data, contentType) {
    var byteCharacters = atob(b64Data)
    
    var byteArrays = []
    
    for (let offset = 0; offset < byteCharacters.length; offset += 512) {
        var slice = byteCharacters.slice(offset, offset + 512),
            byteNumbers = new Array(slice.length)
        for (let i = 0; i < slice.length; i++) {
            byteNumbers[i] = slice.charCodeAt(i)
        }
        var byteArray = new Uint8Array(byteNumbers)
    
        byteArrays.push(byteArray)
    }
    
    var blob = new Blob(byteArrays, { type: contentType })
    return blob}
    

    Then use the createObjectURL method to create a URL you can put query strings on like so:

    URL.createObjectURL(b64toBlob(data.buffer.data, 'application/pdf')) + '#toolbar=0&navpanes=0&scrollbar=0'
    

    Set your object's data attribute to the resulting string and you'll have it.

提交回复
热议问题