📄 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
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- View Models & Data Models
- Controller Endpoints & Usage
- Helper Methods & Utilities
- Error Handling & Return Types
- UML Class Diagram
- Sample Code Blocks & Usage Examples
- Third‑Party Integrations
- 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
- Form Browsing & Management
Index(),ViewForm(),DownloadForm(),UploadForm(),UploadForms()
- PDF Viewer APIs (via Syncfusion)
Load,RenderPdfPages,RenderAnnotationComments,Unload,RenderThumbnailImages,Bookmarks,Download,PrintImages,ExportAnnotations,ImportAnnotations
- File Manager Operations
FileOperations,Upload,Download,GetImage,FormsDirectory
- 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 inwwwroot/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
AcceptsIrbyFormsViewwithIFormFile Fileand 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.) underwwwroot/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
FileManagerResponsewith embeddedErrorDetails. - PDF Viewer: Returns JSON serialized result or HTTP
Contentwith error message. - Upload: Sets HTTP status code according to
uploadResponse.Error.Code. - Exceptions: Word/DocumentEditor throws
NotSupportedExceptionfor 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! 🚀