📄 IrbyFormsController Documentation

Welcome to the comprehensive documentation for IrbyFormsController.cs. This controller is part of the IrbyImaging.UI ASP.NET Core MVC application, responsible for managing form files (PDFs, Word, Excel) and providing rich PDF viewing/editing endpoints via Syncfusion PDF Viewer.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. View Models & Data Models
  5. Controller Endpoints & Usage
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. UML Class Diagram
  9. Sample Code Blocks & Usage Examples
  10. Third‑Party Integrations
  11. Conclusion

🔍 Overview & Purpose

The IrbyFormsController orchestrates:

  • Browsing, viewing, downloading, uploading PDF forms stored under wwwroot/IrbyForms.
  • Serving Syncfusion-based PDF Viewer API endpoints (Load, RenderPdfPages, etc.) for client‑side PDF interaction.
  • Providing file manager operations (read, delete, copy, move, search) via Syncfusion’s PhysicalFileProvider.
  • Handling document editor (Word) and spreadsheet (Excel) file operations.
  • Caching and serving form metadata and file contents securely.

Intended Use: Integrate a web UI where users can browse, upload, view, annotate, and download forms/documents within the IrbyImaging system.


🛠 Dependencies & Technologies

Category Technology / Package
Framework ASP.NET Core MVC (Microsoft.AspNetCore.*)
ORM / DB Context Entity Framework Core (IrbyContext)
File I/O System.IO, Syncfusion.EJ2.FileManager
PDF Processing iTextSharp.text, Syncfusion.EJ2.PdfViewer
Document Editor Syncfusion.EJ2.DocumentEditor
Spreadsheet Syncfusion.EJ2.Spreadsheet, Syncfusion.XlsIO
JSON Serialization Newtonsoft.Json
Caching Microsoft.Extensions.Caching.Memory
Hosting Environment IWebHostEnvironment
Configuration Microsoft.Extensions.Configuration

🔑 Key Functional Areas

  1. Form Browsing & Management
    • Index(), ViewForm(), DownloadForm(), UploadForm(), UploadForms()
  2. PDF Viewer APIs (via Syncfusion)
    • Load, RenderPdfPages, RenderAnnotationComments, Unload, RenderThumbnailImages, Bookmarks, Download, PrintImages, ExportAnnotations, ImportAnnotations
  3. File Manager Operations
    • FileOperations, Upload, Download, GetImage, FormsDirectory
  4. Document Editor & Spreadsheet
    • GetDocument(), GetExcel(), OpenExcel(), SaveExcel()

📑 View Models & Data Models

IrbyFormsView (in IrbyImaging.UI.Models)

Property Type Description
FileName string Name of the document file
FilePath string Absolute path on disk
FormNumber string Extracted numeric form identifier
File IFormFile (on upload) Uploaded file contents

IrbyForms (Entity in IrbyImaging.DomainClasses)

Property Type Description
FormId Guid Unique record identifier
FormNumber string e.g., “Form 01”
FormName string Original file name
ImageContents byte[] Binary data of the uploaded file
DocumentUploadedBy string User who uploaded
DocumentUploadedDate DateTime Timestamp

Auxiliary Classes

  • jsonObjects: Used to deserialize Syncfusion PDF viewer requests (document, pageNumber, annotations, etc.).
  • CustomParams: Represents parameters for Word/CSV/Excel endpoints (FileName, Action).

🚀 Controller Endpoints & Usage

1. Browsing & Viewing

  • GET /IrbyForms/Index
    Lists all PDF forms in wwwroot/IrbyForms.
  • GET /IrbyForms/ViewForm?file={path}
    Displays a selected PDF in a Razor view.
  • GET /IrbyForms/DownloadForm?file={path}
    Streams the PDF back as a download.

2. Uploading Forms

  • GET /IrbyForms/UploadForm
    Renders upload page with dropdown of existing PDFs.
  • POST /IrbyForms/UploadForms
    Accepts IrbyFormsView with IFormFile File and stores binary in database.

3. Syncfusion PDF Viewer API

All routes are under api/IrbyForms/

Action Route Description
Load POST /Load Load PDF (fileName or Base64) into viewer.
RenderPdfPages POST /RenderPdfPages Get rendered page images.
RenderAnnotationComments POST /RenderAnnotationComments Get PDF annotation comments.
Unload POST /Unload Clear PDF cache.
RenderThumbnailImages POST /RenderThumbnailImages Generate page thumbnails.
Bookmarks POST /Bookmarks Extract bookmark structure.
Download POST /Download Return document as Base64.
PrintImages POST /PrintImages Get print-ready page images.
ExportAnnotations POST /ExportAnnotations Serialize existing annotations.
ImportAnnotations POST /ImportAnnotations Load annotations from file.

Example: Loading a PDF

POST /api/IrbyForms/Load
Content-Type: application/json

{
  "document": "form 01.pdf",
  "isFileName": true,
  "password": "",
  "zoomFactor": 1
}

4. File Manager Endpoints

  • POST /IrbyForms/FileOperations
    Manage files & folders (read, delete, copy, move, etc.) under wwwroot/IrbyForms.
  • POST /IrbyForms/Upload
    Upload arbitrary files.
  • POST /IrbyForms/Download
    Download selected files.
  • POST /IrbyForms/GetImage
    Retrieve image thumbnail/preview.

5. Document Editor & Spreadsheet

Action Route Description
GetDocument POST /GetDocument Load Word/PDF as Base64 (PDF) or JSON (Word).
GetExcel POST /GetExcel Return Excel file stream.
OpenExcel POST /OpenExcel Parse uploaded Excel into JSON workbook object.
SaveExcel POST /SaveExcel Save changes back to an Excel file.

🛠 Helper Methods & Utilities

JsonConverterstring(jsonObjects results)

Converts jsonObjects (Syncfusion payload) into a Dictionary<string,string> for generic handling.

public Dictionary<string,string> JsonConverterstring(jsonObjects results) { … }

GetDocumentPath(string document)

Resolves the full path to a document, checking both absolute and under wwwroot/IrbyForms.


⚠️ Error Handling & Return Types

  • File Manager: Returns FileManagerResponse with embedded ErrorDetails.
  • PDF Viewer: Returns JSON serialized result or HTTP Content with error message.
  • Upload: Sets HTTP status code according to uploadResponse.Error.Code.
  • Exceptions: Word/DocumentEditor throws NotSupportedException for unsupported formats.

📐 UML Class Diagram

classDiagram
    IrbyFormsController o-- IrbyContext
    IrbyFormsController o-- IHttpContextAccessor
    IrbyFormsController o-- IWebHostEnvironment
    IrbyFormsController o-- IMemoryCache
    IrbyFormsController o-- IConfiguration
    IrbyFormsController ..> IrbyFormsView
    IrbyFormsController ..> IrbyForms
    IrbyFormsController ..> jsonObjects
    IrbyFormsController ..> CustomParams

    class IrbyFormsView {
      string FileName
      string FilePath
      string FormNumber
      IFormFile File
    }
    class IrbyForms {
      Guid FormId
      string FormNumber
      string FormName
      byte[] ImageContents
      string DocumentUploadedBy
      DateTime DocumentUploadedDate
    }
    class jsonObjects {
      string document
      bool isFileName
      // ... many PDF viewer props
    }
    class CustomParams {
      string FileName
      string Action
    }

💻 Sample Code Blocks & Usage Examples

Browsing Forms in Razor View

@model IEnumerable<IrbyImaging.UI.Models.IrbyFormsView>
<h2>Available Forms 📂</h2>
<ul>
  @foreach(var form in Model) {
    <li>
      @form.FileName
      <a asp-action="ViewForm" asp-route-file="@form.FilePath">View</a> |
      <a asp-action="DownloadForm" asp-route-file="@form.FilePath">Download</a>
    </li>
  }
</ul>

Invoking Syncfusion Load API (JavaScript)

fetch('/api/IrbyForms/Load', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    document: 'Form 01.pdf',
    isFileName: true,
    password: ''
  })
})
.then(res => res.json())
.then(data => {
   pdfViewer.open(data);
});

🔗 Third‑Party Integrations

  • Syncfusion EJ2 PDF Viewer, DocumentEditor, Spreadsheet, FileManager.
  • iTextSharp for low‑level PDF merging (used in ViewAttachment).
  • Newtonsoft.Json for JSON serialization.

🏁 Conclusion

IrbyFormsController is a one‑stop controller that bridges file system form management, database‑backed uploads, and rich client‑side PDF/document interactions. Leveraging Syncfusion’s EJ2 suite, it provides granular control over PDF rendering, annotation, and editing. The file manager APIs round out a powerful UX for handling documents within the IrbyImaging ecosystem.

Next Steps:

  • Integrate with front‑end Razor/Blazor to maximize the client experience.
  • Secure endpoints (add authorization).
  • Extend to other file types (images, video).

Enjoy building with IrbyImaging! 🚀