Content is user-generated and unverified.

Form Report Viewer - Setup Guide

Overview

This solution provides a complete integration between .NET Core API and React frontend for viewing and exporting RDLC reports from SurveyJS forms.

Prerequisites

  • .NET 8.0 SDK
  • Node.js 18+
  • Syncfusion License Key
  • Visual Studio 2022 or VS Code

.NET Core API Setup

1. Create New Project

bash
dotnet new webapi -n FormReportAPI
cd FormReportAPI

2. Install Required Packages

bash
# Syncfusion packages
dotnet add package Syncfusion.ReportWriter.Net.Core --version 24.1.41
dotnet add package Syncfusion.Compression.Net.Core --version 24.1.41
dotnet add package Syncfusion.DocIO.Net.Core --version 24.1.41
dotnet add package Syncfusion.XlsIO.Net.Core --version 24.1.41
dotnet add package Syncfusion.Pdf.Net.Core --version 24.1.41

# Other dependencies
dotnet add package Newtonsoft.Json
dotnet add package Microsoft.AspNetCore.Cors

3. Project Structure

FormReportAPI/
├── Controllers/
│   └── FormReportController.cs
├── Services/
│   ├── IFormReportService.cs
│   └── FormReportService.cs
├── Models/
│   └── FormDataTransformer.cs
├── Reports/
│   └── DynamicFormReport.rdlc
├── Program.cs
└── appsettings.json

4. Configure Syncfusion License

In Program.cs, add your Syncfusion license key:

csharp
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR_LICENSE_KEY_HERE");

5. Create RDLC Report File

Create Reports/DynamicFormReport.rdlc using Visual Studio Report Designer or Syncfusion Report Designer.

6. Update appsettings.json

json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "CorsSettings": {
    "AllowedOrigins": ["http://localhost:3000", "https://localhost:3000"]
  }
}

React Frontend Setup

1. Create React App

bash
npx create-react-app form-report-viewer --template typescript
cd form-report-viewer

2. Install Dependencies

bash
npm install lucide-react
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

3. Configure Tailwind CSS

Update tailwind.config.js:

javascript
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Add to src/index.css:

css
@tailwind base;
@tailwind components;
@tailwind utilities;

4. Update API Base URL

In the React component, update the API URL:

javascript
static baseUrl = 'https://localhost:5001/api/FormReport'; // Your API URL

Usage Examples

1. Basic Implementation

javascript
import FormReportViewer from './components/FormReportViewer';

function App() {
  const formStructure = `{
    "Entity": {
      "FormStructure": {
        "title": "Sample Form",
        "pages": [...]
      }
    }
  }`;

  const formData = `{
    "Entity": {
      "Location": "Test Location",
      "Status": "Completed"
    }
  }`;

  return (
    <div className="App">
      <FormReportViewer 
        formStructureJson={formStructure}
        formDataJson={formData}
      />
    </div>
  );
}

2. Export Only (No Preview)

javascript
import { ReportService } from './services/ReportService';

const handleExport = async () => {
  try {
    const blob = await ReportService.exportReport(
      formStructureJson, 
      formDataJson, 
      'pdf'
    );
    
    // Download file
    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    link.href = url;
    link.download = 'report.pdf';
    link.click();
    URL.revokeObjectURL(url);
  } catch (error) {
    console.error('Export failed:', error);
  }
};

3. API Integration

javascript
// In your React component
const [reports, setReports] = useState([]);

useEffect(() => {
  const fetchReports = async () => {
    try {
      const response = await fetch('/api/forms');
      const forms = await response.json();
      setReports(forms);
    } catch (error) {
      console.error('Failed to fetch forms:', error);
    }
  };

  fetchReports();
}, []);

API Endpoints

POST /api/FormReport/preview

Preview report data

json
{
  "formStructureJson": "...",
  "formDataJson": "..."
}

POST /api/FormReport/export

Export report as file download

json
{
  "formStructureJson": "...",
  "formDataJson": "...",
  "exportFormat": "pdf|excel|word|csv"
}

POST /api/FormReport/export-base64

Export report as base64 string

json
{
  "formStructureJson": "...",
  "formDataJson": "...",
  "exportFormat": "pdf"
}

GET /api/FormReport/formats

Get supported export formats

Running the Application

1. Start .NET Core API

bash
cd FormReportAPI
dotnet run

API will be available at https://localhost:5001

2. Start React App

bash
cd form-report-viewer
npm start

React app will be available at http://localhost:3000

Customization

1. Modify Report Layout

Edit the RDLC file using Visual Studio or Syncfusion Report Designer to customize the report layout.

2. Add Custom Fields

Extend the FormDataTransformer class to handle additional form fields:

csharp
public class CustomFormDataTransformer : FormDataTransformer
{
    public override RdlcReportData TransformFormData(string formJson, string dataJson)
    {
        var result = base.TransformFormData(formJson, dataJson);
        // Add custom transformations
        return result;
    }
}

3. Custom Export Options

Add new export formats by extending the FormReportService:

csharp
public async Task<byte[]> ExportToCustomFormat(string formStructure, string formData)
{
    // Custom export logic
}

Troubleshooting

Common Issues

  1. Syncfusion License Error
    • Ensure you have a valid Syncfusion license
    • Register the license key in Program.cs
  2. CORS Issues
    • Verify CORS policy is configured correctly
    • Check that React app URL is in allowed origins
  3. Report Generation Fails
    • Ensure RDLC file exists in Reports folder
    • Check that DataSet names match RDLC data sources
  4. File Download Issues
    • Verify browser settings allow downloads
    • Check Content-Type headers are set correctly

Debug Tips

  1. Enable detailed logging in appsettings.json:
json
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Information"
    }
  }
}
  1. Use browser dev tools to inspect API responses
  2. Check server logs for detailed error messages

Production Deployment

API Deployment

  1. Publish the API: dotnet publish -c Release
  2. Deploy to IIS, Azure App Service, or Docker container
  3. Update CORS settings for production URLs

React Deployment

  1. Build for production: npm run build
  2. Deploy to static hosting (Netlify, Vercel, Azure Static Web Apps)
  3. Update API base URL for production

Support

Content is user-generated and unverified.
    Setup Guide and Usage Instructions | Claude