PDF viewer is showing Failed to load the page

Dear all,

We have started a project to display .PDF or .MP4 video files.

we choused for files stored with in the mounted folder location. instead of storing the SQL Database for eliminate slow response in query run in long run.

We have completed a few steps:

Step 1: We created a "Mount Folder Path" - folder name: "D:\Digital_SOP_Folder"

Step 2: We created a "Master Data screen" using "FileUpload" with an "OnFileReceived" Script:

   	# --- 1. Get File Information ---
	filename = event.file.name
	filedata = event.file.getBytes() # <-- UNCOMMENTED THIS
	filesize = event.file.size
	file_extension = filename.split('.')[-1].lower()
	# Determine file type
	if file_extension == 'pdf':
	    file_type = 'PDF'
	elif file_extension == 'mp4':
	    file_type = 'MP4'
	else:
	    file_type = 'Other'	
	# Update UI components
	self.getSibling("File_Name").props.text = filename
	self.getSibling("File_Size").props.text = str(round(filesize / 1024.0, 2)) + str(' ~ KB')
	# --- 2. Save the File to the Server ---
	server_folder_path = "D:\\Digital_SOP_Folder\\"
	full_server_path = server_folder_path + filename
	try:
	    system.file.writeFile(full_server_path, filedata)
	except Exception as e:
	    # Handle error - maybe the F: drive is full or permissions are wrong
	    self.getSibling("Label_1").props.text =("Error saving file: " + str(e))	    
	    return
	# --- 3. Construct the CORRECT Web Path ---
	Web_Path = "/webdev/Digital_SOP_Demo/Digital_SOP_Folder/" + filename	
	error_message = ''
	# --- 4. Write to SQL Database ---
	db = "localSQL"
	query = """
	    INSERT INTO StoredFiles (FileName, FileExtension, WebPath)
	    VALUES (?, ?, ?)
	"""
	args = [filename, file_type, Web_Path]	
	try:
		system.db.runPrepUpdate(query, args, db)		
	except Exception as e:
	    error_message = "Error writing to database: {e}"
        self.getSibling("Label_1").props.text = (error_message) # Keep for logging
        

In this script, we are able to read the file, store it in "D:\Digital_SOP_Folder\", and also store the file information in the SQL database.

Step 3: In the Main screen > Dropdown: we get the file name and file ID from the SQL database. In Button > On Action Performed script:

    # Get the ID from dropdown
    file_id = self.getSibling("Dropdown").props.value
    
    system.perspective.print("Selected ID: " + str(file_id))
    
    try:
        # Query database to get filename from ID
        query = "SELECT FileName FROM StoredFiles WHERE FileID = ?"
        result = system.db.runPrepQuery(query, [file_id],"localSQL")
        
        if len(result) > 0:
            filename = result[0]["FileName"]
            system.perspective.print("Filename: " + filename)
            
            # Construct the full file path
            file_path = "D:/Digital_SOP_Folder/" + filename
            
            # Read the PDF file as bytes
            pdf_bytes = system.file.readFileAsBytes(file_path)
            
            # Convert to base64 string
            import base64
            pdf_base64_string = base64.b64encode(pdf_bytes).decode('utf-8')
            
            # Create data URI
            data_uri = "data:application/pdf;base64,{}".format(pdf_base64_string)
            
            # Set to PDF Viewer
            self.getSibling("PDFViewer").props.source = data_uri
            
            system.perspective.print("PDF loaded successfully")
        else:
            system.perspective.print("No file found for ID: " + str(file_id))
            
    except Exception as e:
        system.perspective.print("Error: " + str(e)) 

Issue: Some files the PDF Viewer displays "Failed to load the Page."

We have checked a few points:

  • The folder path is correct

  • File extension is okay

  • File Size is less then 100KB

  • We also checked the URL of the file in Google Chrome browser and the file opens, but in the Ignition PDF viewer it shows "Failed to load the page"

Questions:

  1. Has anyone experienced this issue before?

  2. Are there any known limitations with the PDF Viewer component when using base64 data URIs?

  3. Could this be related to file size limitations?

  4. This approach is better?.

image

What shows up in the gateway log when you try to access the non-working files?

Dear @pturmel,

thanks for your replay.

Please find the attached screen shot for gateway log.

That is unrelated. Your OS is blocking the local multicast packets Ignition uses for auto-discovery of local gateways in the launchers. (You can turn that feature off in the gateway to avoid that noisy report in the log.)

Dear @pturmel ,

thanks for your replay. Also i Disable the checkbox under Config => System => Gateway Settings => Multicast Settings.

Logs in gateway.

image

but still PDF file not showing.

some times it`s working for other PDF files.

  1. You are creating data URLs for your PDF bytes. That completely bypasses WebDev.

  2. Your WebDev actual URL appears to be missing either a project name or a folder mount name.

The gateway loggers you need are probably at DEBUG level. You will need to look for webdev loggers in the gateway's log configuration and set them to DEBUG.

Dear @pturmel ,

Thanks for your response. I have added a new Dropdown with the script below:

    selected_id = self.props.value  # This will be the selected ID (e.g., 2)
    selected_filename = None
    for option in self.props.options:
        if option["FileID"] == selected_id:
            File_Name11 = option["FileName"]
            
    
    
    self.getSibling("PDFViewer").props.source = "http://localhost:8088/system/webdev/Digital_SOP_Demo/Digital_SOP_Folder/" +str(File_Name11)
    
    

gateway log:

::::::::: but still some times “Failed to load the page‘

*******************************

I noticed that the file opens successfully for the first 4-5 attempts, but then it starts showing an error. After that, no matter how many times I try, the error persists.

Can you suggest which approach is better for my use case:

  1. Folder Mount approach: Save the files in a mounted folder location and read the file path from the database

  2. Database storage approach: Store the actual file binary data directly in the SQL Database

Hi,

I found the solution for this. in PDF Viewer Page number is grater then Page Count.

1 Like