Your code is querying a database, retrieving a row, outputting the content of a field to a file, then pointing a web browser at that file.
To have a web browser open your PDF without saving it on the filesystem, you need to restructure your code to operate as an HTTP server. You will create an HTTP server instance, and wait for a connection from a client. Once you have that connection, you will query the database and output the PDF file binary data to the web client. This will require constructing an HTTP header with a
Content-type: application/pdf
. The header will be followed by an extra newline character, followed by the binary of the PDF file.
I think this link will give you the building blocks to do this.
Python, create a Web (HTTP) server[
^]
A valid HTTP response containing a PDF might look like:
HTTP/1.1 200 OK
Content-Type: application/pdf
Last-Modified: Thu, 10 Jul 2014 18:52:24 GMT
Accept-Ranges: bytes
ETag: "0e43616709ccf1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sun, 29 Oct 2023 21:48:13 GMT
Content-Length: 1593751
%PDF-1.4
% 쏢
1 0 obj
<<
/Type /Catalog
/Outlines 3 0 R
/Pages 4 0 R
/Dests 5 0 R
/AcroForm 6 0 R
.. etc.