Ignition can display and store PDF files from data stored in databases. In a database, each column is a certain datatype. The datatype where you can store PDF bytes is a LONGBLOB datatype, therefore to insert the PDF file's bytes to a column the column's datatype must be a LONGBLOB.
Displaying PDF files from the database
Ignition can render the PDF inside the PDF viewer component, which is a part of the Reporting Module To view PDF files in the Client, your Ignition server must have this module. Once the module is installed, you can load the bytes from the database into the PDF viewer component with the following script which is enacted on a drop-down component property event handler.
# Get the id from the dropdown.
id = event.newValue
# Query for the raw pdf data and name by using the id.
bytes = system.db.runScalarQuery("SELECT data FROM documents WHERE id = %d" % id)
name = system.db.runScalarQuery("SELECT name FROM documents WHERE id = %d" % id)
# Load the bytes and the name into the PDF viewer component.
event.source.parent.getComponent('PDF Viewer').loadPDFBytes(bytes, name)
Uploading PDF files to the database
Ignition can upload PDF documents to a database. Imagine the user pressing a button, a file browser pops up, the user selects the PDF file, presses enter and the file gets uploaded into the database. The following script demonstrates how this might work:
# Find the path to the PDF file.
path = system.file.openFile("pdf")
# Read the file as bytes, and ask the user for a filename.
data = system.file.readFileAsBytes(path)
name = system.gui.inputBox("Enter a name for the file")
# Insert the data and name into the database.
system.db.runPrepUpdate("INSERT INTO documents (name, data) VALUES (?,?)", [name,data])