[{"id":"5efffa63-6bf4-4819-8af7-0f6b8e1c53a4","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"dfd416a6-eef9-49a0-bb8b-2e739da5cc1c","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"3b1e4fc6-fe58-48c3-b090-4335186ca05c","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"7f93f7b9-9f7f-46b2-b05f-494017b34eae","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"95079239-11e6-44bd-8e3f-4c5b9f8e172c","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"43ece935-4016-4eb3-a3f8-5951257cb2a7","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"b2fdc309-b91f-42a8-b6f5-5c04d366748e","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"bb982598-dc4e-4495-884c-64f4338def46","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"c632c625-e3a4-4a10-abfa-66bf4a2cd520","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"8fc7bf9e-d24f-43cd-a915-6f8a991152c4","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"7e488fdd-64d8-4c8f-9f96-7a9590f02070","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"4d93a50e-208e-44ef-8ea6-8e81d4c8f339","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"e77dbdc2-200d-4c9c-9bf7-907a453eccb0","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"eecc4b5c-431b-4677-887b-a523a0d10cfd","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"ba126ca3-9e37-4aed-b486-a79bd39b3d86","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]},{"id":"5792319e-7207-4871-a69d-aa3b6eabad63","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"eb1cc175-3766-46e9-9659-c125771a58d4","tags":[{"name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3"}]},{"id":"212b23f1-4bfe-46f9-91cf-f24eca55418d","tags":[{"name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601","links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e"}]}]
        
(Showing Draft Content)

Get Started with ActiveReportsJS Report Viewer in a Svelte.js application

Create Svelte application

The easiest way to create a Svelte application is to use the SvelteKit tool. Run the following command from the command prompt or terminal:

npm create svelte@latest arjs-svelte-viewer-app

It will ask several questions and below the list of recommended answers

√ Which Svelte app template? » Skeleton project
√ Add type checking with TypeScript? » Yes, using TypeScript syntax
√ Add ESLint for code linting? » No
√ Add Prettier for code formatting? » Yes
√ Add Playwright for browser testing? » No
√ Add Vitest for unit testing? » No

Once the command run successfully, you could open the newly created arjs-svelte-viewer-app in your favorite IDE, such as Visual Studio Code.

Install ActivereportsJS npm package

The @grapecity/activereports npm package contains the pure ActiveReportsJS Report Viewer component that could be integrated into a Svelte application.

To install the latest version of this package, run the following command from the application's root folder.

npm install @grapecity/activereports@latest
# or if you use yarn
yarn add @grapecity/activereports@latest 

Configure Vite.js

Svelte uses Vite.js under the hood to run applications in development mode and build them for production. To get ActiveReportsJS working with Vite.js, we need to adjust the Vite.js configuration. Create a new file called alias.js in the root of the application and add the following code:

import moment from "./node_modules/moment";

export const { fn, min, max, now, utc, unix, months,
  isDate, locale, invalid, duration, isMoment, weekdays,
  parseZone, localeData, isDuration, monthsShort, weekdaysMin,
  defineLocale, updateLocale, locales, weekdaysShort, normalizeUnits,
  relativeTimeRounding, relativeTimeThreshold, calendarFormat, ISO_8601
} = moment;

export default moment;

Then open the vite.config.js file in the root folder of the application and replace its content with the following:

import { sveltekit } from '@sveltejs/kit/vite';
import path from "path";

/** @type {import('vite').UserConfig} */
const config = {
  plugins: [sveltekit()],
  resolve: {
    alias: [
      {
        find: /^moment$/,
        replacement: path.resolve(__dirname, "./alias.js"),
      },
      {
        find: /^gc-dv$/,
        replacement: path.resolve(
          __dirname,
          "./node_modules/@grapecity/activereports/lib/node_modules/gc-dv.js"
        ),
      },
      {
        find: /^\@grapecity\/ar-js-pagereport$/,
        replacement: path.resolve(
          __dirname,
          "./node_modules/@grapecity/activereports/lib/node_modules/@grapecity/ar-js-pagereport.js"
        ),
      },
      {
        find: /^barcodejs$/,
        replacement: path.resolve(
          __dirname,
          "./node_modules/@grapecity/activereports/lib/node_modules/barcodejs.js"
        ),
      },
    ],
  },
};
export default config;

Add ActiveReportsJS report to the application

ActiveReportsJS uses the JSON format and the rdlx-json extension for report template files.

In the static folder of the application, create a new file called report.rdlx-json and insert the following content into it.

{
  "Name": "Report",
  "Body": {
    "ReportItems": [
      {
        "Type": "textbox",
        "Name": "TextBox1",
        "Value": "Hello, ActiveReportsJS Viewer",
        "Style": {
          "FontSize": "18pt",
          "PaddingLeft": "5pt",
          "PaddingTop": "5pt"          
        },
        "Width": "8.5in",
        "Height": "0.5in"
      }
    ]
  }
}

Add Report Viewer component to the application

Replace the default content of the src\routes\+page.svelte file with the following code

<script lang="ts">
    import "@grapecity/activereports/styles/ar-js-ui.css";
    import "@grapecity/activereports/styles/ar-js-viewer.css";    
    import {Viewer} from "@grapecity/activereports/reportviewer";
    import {PdfExport, HtmlExport, TabularDataExport} from "@grapecity/activereports";
    import { onMount } from 'svelte';
   
    onMount(() => {
        let viewer = new Viewer("#viewer-host");
        viewer.open("report.rdlx-json");
    });
</script>

<div id="viewer-host"></div>

<style>
    #viewer-host {
        width: 100%;
        height: 100vh;
    }
</style>

Disable server-side rendering

By default, SvelteKit will render any page first on the server and send it to the client as HTML. But ActiveReportsJS can only operate on the client-side. Hence, we need to disable the server-side rendering for the page that contains the Report Viewer. We can do that by adding the +page.js file with the following content alongside the +page.svelte

export const prerender = false;
export const ssr = false;

Run and test the application

You can run the application by using the yarn run dev or npm run dev commands. By default, the project runs at http://localhost:5173/.

If you browse this URL, the ActiveReportsJS Report Viewer will appear on the page. The viewer will display the report that shows the Hello, ActiveReportsJS Viewer text. You can test the basic functionality by using the Report Viewer User Interface. The Report Viewer component exposes a rich API supplied with TypeScript declarations, so you can easily use it within a Svelte application.