Hash data parameters for data URIs (hide the PDF toolbar for data URIs)

I have a base64 encoded pdf database URI.

eg:

return <object data="data:application/pdf;base64,JVBERi0xLjMKJf////8KOCAwIG9...VmCjI0MTU4OAolJUVPRgo=" type="application/pdf"></object>

I can embed it in a page without any problems. However, by default, browsers include a toolbar in PDF format.

PDF toolbar example

It seems that the only way to disable this toolbar is to include some hash options at the end of the URL.

eg.

<object data="path/to/file.pdf#toolbar=0&navpanes=0&scrollbar=0" type="application/pdf"></object>

Which works fine if the PDF is accessed via a relative path or URL, but I cannot find a way to do this work with the data URI.

Can these hash parameters be included at the end of the URI?

Or does anyone know some way to hide this toolbar in another way?

Any help is appreciated. Thanks in advance.:)

+4
2

, , ,

https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs

( " " ):

.. URI , ( - ) URI , URI.

, .

PDF , (, iText), , , ( )

stamper.setEncryption(null,null, PdfWriter.HideWindowUI, PdfWriter.STRENGTH40BITS); 
stamper.setViewerPreferences(PdfWriter.HideToolbar);

. (: http://developers.itextpdf.com/question/how-disable-save-button-and-hide-menu-bar-adobe-reader)

embed ( object), ho hum.

+3

, URI . URI URL- blob .

base64 pdf- :

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}

createObjectURL URL-, :

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

, .

0

Source: https://habr.com/ru/post/1628566/


All Articles