Home » Javascript » Restricting download of PDF and TIFF files

Restricting download of PDF and TIFF files

Posted by: admin August 19, 2018 Leave a comment

Questions:

Currently I have a requirement wherein I am receiving TIFF and PDF files encoded in base64. I am decoding it and then it is getting downloaded to the user’s system. Now I am being asked to restrict download(from the browser settings through a plugin if possible, if not then through code) such that people can only view this document in the window and not download it. Kindly offer me solutions to this.

Browser: Internet explorer 11
Technologies used: JSP,javascript

I am pasting here the relevant code sample for PDF. We are using similar code for TIFF.

if(imageType.equals("pdf") || imageType.equals("PDF"))
            {
                 String encodedBytes = respons;
                try 
                {
                    OrbiLogger.println("Inside pdf");
                    BASE64Decoder decoder = new BASE64Decoder();
                    byte[] decodedBytes;
                    decodedBytes = new 
                    BASE64Decoder().decodeBuffer(encodedBytes);
                    response.setHeader("Content-Type", "application/pdf");
                    response.setHeader("Content- 
                    Disposition","inline;filename="+fileName);
                    response.setHeader("Content- 
                    Length",String.valueOf(decodedBytes.length));
                    DataOutputStream os = new 
                    DataOutputStream(response.getOutputStream());
                    os.write(decodedBytes, 0, decodedBytes.length);
                    os.flush();
                    os.close();
                    OrbiLogger.println("Created");
                } catch (Exception e) {
                    OrbiLogger.println("pdf exception");
                    e.printStackTrace();
                }
            }
Answers: