From 22378789e2a112bf71d499236a5c1da11fc7b0e7 Mon Sep 17 00:00:00 2001
From: Joshua Taillon <jat255@gmail.com>
Date: Wed, 5 Sep 2018 22:58:38 -0400
Subject: [PATCH] add option for inline vs. attachment for document rendering

---
 paperless.conf.example |  4 ++++
 src/documents/views.py | 10 ++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/paperless.conf.example b/paperless.conf.example
index d47e4d453..996b816f8 100644
--- a/paperless.conf.example
+++ b/paperless.conf.example
@@ -117,6 +117,10 @@ PAPERLESS_EMAIL_SECRET=""
 # http://paperless.readthedocs.org/en/latest/consumption.html#hooking-into-the-consumption-process
 #PAPERLESS_POST_CONSUME_SCRIPT="/path/to/an/arbitrary/script.sh"
 
+# By default, when clicking on a document within the web interface, the
+# browser will prompt the user to save the document to disk. By uncommenting
+# the below, the document will instead be opened in the browser, if possible.
+#PAPERLESS_INLINE_DOC="true"
 
 #
 # The following values use sensible defaults for modern systems, but if you're
diff --git a/src/documents/views.py b/src/documents/views.py
index e297e0984..4f71deb56 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -1,6 +1,8 @@
 from django.http import HttpResponse, HttpResponseBadRequest
 from django.views.generic import DetailView, FormView, TemplateView
 from django_filters.rest_framework import DjangoFilterBackend
+from django.conf import settings
+
 from paperless.db import GnuPG
 from paperless.mixins import SessionOrBasicAuthMixin
 from paperless.views import StandardPagination
@@ -60,8 +62,12 @@ class FetchView(SessionOrBasicAuthMixin, DetailView):
             self._get_raw_data(self.object.source_file),
             content_type=content_types[self.object.file_type]
         )
-        response["Content-Disposition"] = 'attachment; filename="{}"'.format(
-            self.object.file_name)
+
+        print("OPEN_DOCUMENT", settings.INLINE_DOC)
+        DISPOSITION = 'inline' if settings.INLINE_DOC else 'attachment'
+
+        response["Content-Disposition"] = '{}; filename="{}"'.format(
+            DISPOSITION, self.object.file_name)
 
         return response