@slickgrid-universal/pdf-export 0.0.1 → 9.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +53 -29
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/pdfExport.service.d.ts +88 -0
- package/dist/pdfExport.service.d.ts.map +1 -0
- package/dist/pdfExport.service.js +613 -0
- package/dist/pdfExport.service.js.map +1 -0
- package/package.json +40 -7
- package/src/index.ts +1 -0
- package/src/pdfExport.service.spec.ts +2080 -0
- package/src/pdfExport.service.ts +737 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) 2020-present, Ghislain B.
|
|
2
|
+
https://github.com/ghiscoding/slickgrid-universal
|
|
3
|
+
|
|
4
|
+
and the original author of SlickGrid
|
|
5
|
+
Michael Leibman, michael{dot}leibman{at}gmail{dot}com
|
|
6
|
+
http://github.com/mleibman/slickgrid
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
9
|
+
a copy of this software and associated documentation files (the
|
|
10
|
+
"Software"), to deal in the Software without restriction, including
|
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
14
|
+
the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be
|
|
17
|
+
included in all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
23
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
24
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
25
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,45 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://opensource.org/licenses/MIT)
|
|
2
|
+
[](http://www.typescriptlang.org/)
|
|
3
|
+
[](https://github.com/ghiscoding/lerna-lite)
|
|
4
|
+
[](https://www.npmjs.com/package/@slickgrid-universal/pdf-export)
|
|
5
|
+
[](https://www.npmjs.com/package/@slickgrid-universal/pdf-export)
|
|
6
|
+
[](https://bundlephobia.com/result?p=@slickgrid-universal/pdf-export)
|
|
2
7
|
|
|
3
|
-
##
|
|
8
|
+
## PDF Export Service
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
#### `@slickgrid-universal/pdf-export`
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
Export your SlickGrid data to PDF format using [`jsPDF`](https://www.npmjs.com/package/jspdf) - a popular, well-supported PDF library for JavaScript.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
### External Dependencies
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@slickgrid-universal/pdf-export`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
16
|
+
- [`jsPDF`](https://www.npmjs.com/package/jspdf) to build and export to PDF.
|
|
15
17
|
|
|
16
|
-
##
|
|
18
|
+
## Installation
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
```bash
|
|
21
|
+
npm install @slickgrid-universal/pdf-export
|
|
22
|
+
```
|
|
19
23
|
|
|
20
|
-
##
|
|
24
|
+
## Usage
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
```typescript
|
|
27
|
+
import { PdfExportService } from '@slickgrid-universal/pdf-export';
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
29
|
+
// Register the service
|
|
30
|
+
const pdfExportService = new PdfExportService();
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
// Initialize in grid options
|
|
33
|
+
const gridOptions = {
|
|
34
|
+
enablePdfExport: true,
|
|
35
|
+
pdfExportOptions: {
|
|
36
|
+
filename: 'my-grid-export',
|
|
37
|
+
pageOrientation: 'landscape',
|
|
38
|
+
pageSize: 'a4',
|
|
39
|
+
documentTitle: 'My Grid Data'
|
|
40
|
+
},
|
|
41
|
+
externalResources: [pdfExportService]
|
|
42
|
+
};
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
// Export to PDF
|
|
45
|
+
await pdfExportService.exportToPdf({
|
|
46
|
+
filename: 'custom-export',
|
|
47
|
+
pageOrientation: 'portrait'
|
|
48
|
+
});
|
|
49
|
+
```
|
|
36
50
|
|
|
37
|
-
##
|
|
51
|
+
## Options
|
|
38
52
|
|
|
39
|
-
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
53
|
+
See [PdfExportOption](../common/src/interfaces/pdfExportOption.interface.ts) for all available options.
|
|
42
54
|
|
|
43
|
-
|
|
55
|
+
## Features
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
- Export grid data to PDF
|
|
58
|
+
- Support for grouped data
|
|
59
|
+
- Configurable page size and orientation (A4, Letter, Legal)
|
|
60
|
+
- Portrait and landscape orientations
|
|
61
|
+
- Custom font sizes
|
|
62
|
+
- Support for formatters
|
|
63
|
+
- HTML entity decoding
|
|
64
|
+
- Data sanitization
|
|
65
|
+
- Powered by `jsPDF` (widely used, extensible, and feature-rich)
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { PdfExportService as BasePdfExportService, Column, ContainerService, ExternalResource, GridOption, KeyTitlePair, Locale, PdfExportOption, PubSubService, SlickDataView, SlickGrid, TranslaterService } from '@slickgrid-universal/common';
|
|
2
|
+
export interface GroupedHeaderSpan {
|
|
3
|
+
title: string;
|
|
4
|
+
span: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class PdfExportService implements ExternalResource, BasePdfExportService {
|
|
7
|
+
protected _exportOptions: PdfExportOption;
|
|
8
|
+
protected _grid: SlickGrid;
|
|
9
|
+
protected _groupedColumnHeaders?: Array<GroupedHeaderSpan>;
|
|
10
|
+
protected _columnHeaders: Array<KeyTitlePair>;
|
|
11
|
+
protected _hasGroupedItems: boolean;
|
|
12
|
+
protected _locales: Locale;
|
|
13
|
+
protected _pubSubService: PubSubService | null;
|
|
14
|
+
protected _translaterService: TranslaterService | undefined;
|
|
15
|
+
/** PdfExportService class name which is use to find service instance in the external registered services */
|
|
16
|
+
readonly className = "PdfExportService";
|
|
17
|
+
constructor();
|
|
18
|
+
protected get _datasetIdPropName(): string;
|
|
19
|
+
/** Getter of SlickGrid DataView object */
|
|
20
|
+
get _dataView(): SlickDataView;
|
|
21
|
+
/** Getter for the Grid Options pulled through the Grid Object */
|
|
22
|
+
protected get _gridOptions(): GridOption;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the Service
|
|
26
|
+
* @param grid
|
|
27
|
+
* @param containerService
|
|
28
|
+
*/
|
|
29
|
+
init(grid: SlickGrid, containerService: ContainerService): void;
|
|
30
|
+
/**
|
|
31
|
+
* Export the Grid result to PDF format using jsPDF & jsPDF-AutoTable
|
|
32
|
+
* This is a WYSIWYG export to file output (What You See is What You Get)
|
|
33
|
+
*
|
|
34
|
+
* Example: exportToPdf({ filename: 'my-export', pageOrientation: 'landscape' })
|
|
35
|
+
*/
|
|
36
|
+
exportToPdf(options?: PdfExportOption): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Get all the grid row data and return that as a 2D array
|
|
39
|
+
*/
|
|
40
|
+
protected getAllGridRowData(columns: Column[], columnExportOptionsCache?: Record<string, PdfExportOption>): any[][];
|
|
41
|
+
/**
|
|
42
|
+
* Download the PDF file to the user's computer
|
|
43
|
+
*/
|
|
44
|
+
protected downloadPdf(pdfBytes: Uint8Array, filename: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get all header titles and their keys, translate the title when required.
|
|
47
|
+
* @param {Array<object>} columns of the grid
|
|
48
|
+
*/
|
|
49
|
+
protected getColumnHeaders(columns: Column[]): Array<KeyTitlePair>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the data of a regular row (a row without grouping)
|
|
52
|
+
* @param {Array<Object>} columns - column definitions
|
|
53
|
+
* @param {Number} row - row index
|
|
54
|
+
* @param {Object} itemObj - item datacontext object
|
|
55
|
+
*/
|
|
56
|
+
protected readRegularRowData(columns: Column[], row: number, itemObj: any, columnExportOptionsCache?: Record<string, PdfExportOption>): any[];
|
|
57
|
+
/**
|
|
58
|
+
* Get the grouped title(s) and its group title formatter
|
|
59
|
+
* For example if we grouped by salesRep, the returned result would be: 'Sales Rep: John Dow (2 items)'
|
|
60
|
+
* @param itemObj
|
|
61
|
+
*/
|
|
62
|
+
protected readGroupedTitleRow(itemObj: any): any[];
|
|
63
|
+
/**
|
|
64
|
+
* Get the grouped totals (below the regular rows), these are set by Slick Aggregators.
|
|
65
|
+
* For example if we grouped by "salesRep" and we have a Sum Aggregator on "sales",
|
|
66
|
+
* then the returned output would be:: ["Sum 123$"]
|
|
67
|
+
* @param itemObj
|
|
68
|
+
*/
|
|
69
|
+
protected readGroupedTotalRow(columns: Column[], itemObj: any): any[];
|
|
70
|
+
/**
|
|
71
|
+
* Get all Grouped Header Titles and their keys, translate the title when required.
|
|
72
|
+
* Returns array of { title, span } for each group, in order
|
|
73
|
+
* @param {Array<object>} columns of the grid
|
|
74
|
+
*/
|
|
75
|
+
protected getColumnGroupedHeaderTitles(columns: Column[]): Array<{
|
|
76
|
+
title: string;
|
|
77
|
+
span: number;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Draw the pre-header row (grouped column headers) on the PDF document
|
|
81
|
+
*/
|
|
82
|
+
private _drawPreHeaderRow;
|
|
83
|
+
/**
|
|
84
|
+
* Draw the header row on the PDF document
|
|
85
|
+
*/
|
|
86
|
+
private _drawHeaderRow;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=pdfExport.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfExport.service.d.ts","sourceRoot":"","sources":["../src/pdfExport.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,IAAI,oBAAoB,EACxC,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,MAAM,EACN,eAAe,EACf,aAAa,EACb,aAAa,EACb,SAAS,EACT,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAwBrC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;C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