[{"id":"425f2be4-b65d-4cdf-b543-fb4397f51672","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"a1041c29-1f9f-497e-b577-3e673e487c51","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"c1e3b2a0-7159-4980-a5e1-4fbb04c7fcc1","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"128acbbc-5c49-416b-9c1f-91f679362b23","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"3bc7a653-1dd3-4a33-b35c-41b0ddc2f446","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"cecedb46-bf12-401c-a04c-5282e11b8274","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"2f1768df-3e8b-41c2-826e-93f1a82273d1","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"d9528848-3bae-42c1-8f6d-410a78341cef","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"2683b3de-5c23-429d-9a88-4917616d20ad","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"b96827a0-6bd4-4184-86a4-6fe503d0e4b4","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"96d2140c-5bb6-49b6-a4c7-4af4b7de2e52","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"11f27d32-9547-4a8c-9e88-5dd2bffffeda","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"d186bc7e-cbae-4d23-9cd9-a54880be8e4d","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"26754bf1-707e-4815-b6d3-dcdc87a59188","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"e4c0a89e-cceb-4863-a30a-dff94f1d8d08","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"c4f826a6-5d16-4399-8f1a-7b8449594941","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"ff2b9815-2596-47f7-8793-3585c9ee24a2","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"46851ce2-51a2-4af4-969d-9fe989997135","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"e3e87330-5250-4923-9cdf-e7e8afd353ab","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"a04db983-f77b-4ec6-857c-1c01afaed85a","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"434eed34-9059-46e4-88f9-15e47d09622c","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"30988f2a-ebd5-4a8c-b20e-54a11a528d30","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"a59719c8-0df2-44e1-b89c-9d8fa0312857","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"4be1ecee-287b-43a2-ba99-cfa89de88187","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"ea04cced-7866-48e5-a5fe-1e9f11004d59","tags":[{"product":null,"links":null,"id":"fe610228-9cf6-417f-813a-dcbfd25406c3","name":"upd","color":"#7e678a","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]},{"id":"ab17d080-0112-4ba4-8dae-ef367bec7b78","tags":[{"product":null,"links":null,"id":"4d7b6a40-ab32-4c71-a381-58f3ffd2653e","name":"new","color":"#ed7422","productId":"d699a6af-e150-4da3-ab30-25fd97934601"}]}]
In addition to the Report Viewer and the Report Designer components, ActiveReportsJS provides a set of APIs that allow you to create reports programmatically and export them to PDF, Excel, and HTML formats. This feature is handy for developers who want to implement a custom report designer or custom report viewer or build, run, and export reports without using an interactive UI. This tutorial shows how to use the API to create a simple report programmatically and export it to PDF. We use React.js + Typescript as the framework for this tutorial, but the techniques described here also apply to other frameworks. To get the most out of the API, we recommend using Typescript because the API is supplied with the type declarations recognizable by the IntelliSense feature of Visual Studio Code or other IDE that supports TypeScript.
The easiest way to create a new React application is to use the Create React App tool. Run the following command from the command prompt or terminal to create a React application from the Typescript
template. For details, see Getting Started on the Create React App site.
# npm 6.x
npm init react-app arjs-api --template typescript
# npm 7+, extra double-dash is needed
npm init react-app arjs-api -- --template typescript
Or if you are using yarn:
yarn create react-app arjs-api --template typescript
For more ways to create a React application, see the official documentation
The ActiveReportsJS API is distributed via @mescius/activereportsjs npm package. The same package contains the export filters and other core functionality.
To install the current version of this package, run the following command from the application's root folder.
npm install @mescius/activereportsjs@latest
Or if you are using yarn:
yarn add @mescius/activereportsjs@latest
In the src
folder, create a new file called reportService.ts
with the following content:
import { Rdl as ARJS, PageReport } from "@mescius/activereportsjs/core";
import { PdfExport } from "@mescius/activereportsjs";
export function buildReportDefinition(): ARJS.Report {
const report: ARJS.Report = {};
report.Width = "8.5in";
report.Page = {
TopMargin: "0.5in",
BottomMargin: "0.5in",
LeftMargin: "0.5in",
RightMargin: "0.5in",
PageWidth: "8.5in",
PageHeight: "11in",
};
const textbox: ARJS.Textbox = { Type: "textbox", Name: "txtGreetings" };
textbox.Value = "Hello, ActiveReportsJS";
textbox.Style = {
FontSize: "18pt",
};
textbox.Width = "7in";
textbox.Height = "0.5in";
report.Body = { ReportItems: [textbox] };
return report;
}
export async function exportReport(
reportDefinition: ARJS.Report
): Promise<PdfExport.PdfExportResult> {
const pageReport = new PageReport();
await pageReport.load(reportDefinition);
const doc = await pageReport.run();
return PdfExport.exportDocument(doc, {
info: {
title: "Generated by ActiveReportsJS",
},
});
}
The first function builds the report definition by using the Core API of ActiveReportsJS. The second function exports the report to PDF by using the PDF Export API
Open the src\App.tsx
file and replace its content with the following code.
import "./App.css";
import { buildReportDefinition, exportReport } from "./reportService";
function App() {
return (
<div className="App">
<header className="App-header">
<a
className="App-link"
href="."
onClick={(e) => {
e.preventDefault();
const reportDefinition = buildReportDefinition();
exportReport(reportDefinition)
.then((result) => {
result.download("ActiveReportsJSReport");
})
.catch(console.error);
}}
>
Generate Report
</a>
</header>
</div>
);
}
export default App;
Running the npm start
or yarn start
commands could fail with the fatal error that the JavaScript heap is out of memory. In that case, open the package.json
file and replace the start
script with the following one.
react-scripts --max_old_space_size=8192 start
Then re-run the npm start
or yarn start
command. If the command fails with an error like the one below, or a similar one, delete the node_modules
folder and run npm install
or yarn
to re-install all the required packages. Then run npm start
or yarn start
again.
> react-scripts start
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'react'
When the application starts, click the "Generate Report" link to build and export the report. The PDF document will be opened in the browser, in the external program, or processed to download depending on the browser settings.