@idevs/corelib 0.0.94 → 0.0.95
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.
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { IdevsExportOptions } from '../globals';
|
|
2
2
|
export declare function doExportPdf(options: IdevsExportOptions): void;
|
|
3
|
+
export type generatePdfOption = {
|
|
4
|
+
unit?: string;
|
|
5
|
+
format?: string;
|
|
6
|
+
orientation?: string;
|
|
7
|
+
margin?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function generatePdf(content: string, option?: generatePdfOption): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { deepClone, postToService } from '@serenity-is/corelib';
|
|
2
|
+
import html2pdf from 'html2pdf.js';
|
|
2
3
|
export function doExportPdf(options) {
|
|
3
4
|
const grid = options.grid;
|
|
4
5
|
const request = deepClone(grid.getView().params);
|
|
@@ -23,4 +24,28 @@ export function doExportPdf(options) {
|
|
|
23
24
|
request.entity = options.entity;
|
|
24
25
|
postToService({ service: options.service, request: request, target: '_blank' });
|
|
25
26
|
}
|
|
27
|
+
export function generatePdf(content, option) {
|
|
28
|
+
const margin = option?.margin ?? 10;
|
|
29
|
+
const unit = option?.unit ?? 'mm';
|
|
30
|
+
const format = option?.format ?? 'a4';
|
|
31
|
+
const orientation = option?.orientation ?? 'portrait';
|
|
32
|
+
if (content) {
|
|
33
|
+
html2pdf()
|
|
34
|
+
.from(content)
|
|
35
|
+
.set({
|
|
36
|
+
margin: margin,
|
|
37
|
+
filename: 'filename.pdf',
|
|
38
|
+
image: { type: 'jpeg', quality: 0.98 },
|
|
39
|
+
html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true },
|
|
40
|
+
jsPDF: { unit: unit, format: format, orientation: orientation },
|
|
41
|
+
})
|
|
42
|
+
.toPdf()
|
|
43
|
+
.get('pdf')
|
|
44
|
+
.then((pdf) => {
|
|
45
|
+
const blob = pdf.output('blob');
|
|
46
|
+
const url = URL.createObjectURL(blob);
|
|
47
|
+
window.open(url, '_blank');
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
26
51
|
//# sourceMappingURL=pdfExportHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfExportHelper.js","sourceRoot":"","sources":["../../src/helpers/pdfExportHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"pdfExportHelper.js","sourceRoot":"","sources":["../../src/helpers/pdfExportHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAE/D,OAAO,QAAQ,MAAM,aAAa,CAAA;AAGlC,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IACzB,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAuB,CAAA;IACtE,OAAO,CAAC,IAAI,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,IAAI,GAAG,CAAC,CAAA;IAChB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAA;IACpC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,GAAG,MAAM,CAAA;IACvB,CAAC;IAED,OAAO,CAAC,aAAa,GAAG,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,CAAA;IAC3C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IAC7D,CAAC;IACD,OAAO,CAAC,aAAa,GAAG,OAAO,CAA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AK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE;SAChE,CAAC;aACD,KAAK,EAAE;aACP,GAAG,CAAC,KAAK,CAAC;aACV,IAAI,CAAC,CAAC,GAAU,EAAE,EAAE;YACnB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;YACrC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;IACN,CAAC;AACH,CAAC","sourcesContent":["import { deepClone, postToService } from '@serenity-is/corelib'\nimport { IdevsExportOptions, IdevsExportRequest } from '../globals'\nimport html2pdf from 'html2pdf.js'\nimport { jsPDF } from 'jspdf'\n\nexport function doExportPdf(options: IdevsExportOptions): void {\n const grid = options.grid\n const request = deepClone(grid.getView().params) as IdevsExportRequest\n request.Take = 0\n request.Skip = 0\n const sortBy = grid.getView().sortBy\n if (sortBy) {\n request.Sort = sortBy\n }\n\n request.ExportColumns = []\n const columns = grid.getGrid().getColumns()\n for (const column of columns) {\n request.ExportColumns.push(column.id || column.field || '')\n }\n request.ExportColumns = request.ExportColumns.filter(column => !!column)\n request.viewName = options.viewName\n request.companyName = options.companyName\n request.reportName = options.reportName\n request.selectionRange = options.selectionRange\n request.conditionRange = options.conditionRange\n request.logo = options.logo\n request.entity = options.entity\n\n postToService({ service: options.service, request: request, target: '_blank' })\n}\n\nexport type generatePdfOption = {\n unit?: string\n format?: string\n orientation?: string\n margin?: number\n}\n\nexport function generatePdf(content: string, option?: generatePdfOption): void {\n const margin = option?.margin ?? 10\n const unit = option?.unit ?? 'mm'\n const format = option?.format ?? 'a4'\n const orientation = option?.orientation ?? 'portrait'\n if (content) {\n html2pdf()\n .from(content)\n .set({\n margin: margin,\n filename: 'filename.pdf',\n image: { type: 'jpeg', quality: 0.98 },\n html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true },\n jsPDF: { unit: unit, format: format, orientation: orientation },\n })\n .toPdf()\n .get('pdf')\n .then((pdf: jsPDF) => {\n const blob = pdf.output('blob')\n const url = URL.createObjectURL(blob)\n window.open(url, '_blank')\n })\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idevs/corelib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.95",
|
|
4
4
|
"description": "Extended library for Serenity Framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,11 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@serenity-is/tsbuild": "^8.6.0",
|
|
43
|
+
"@types/jspdf": "^2.0.0",
|
|
43
44
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
44
45
|
"@typescript-eslint/parser": "^5.62.0",
|
|
45
46
|
"bootstrap": "^5.3.3",
|
|
46
47
|
"eslint": "^8.57.0",
|
|
47
48
|
"eslint-config-prettier": "^8.10.0",
|
|
49
|
+
"html2pdf.js": "^0.10.2",
|
|
50
|
+
"jspdf": "^2.5.1",
|
|
48
51
|
"prettier": "^2.8.8",
|
|
49
52
|
"typescript": "^5.5.4"
|
|
50
53
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module 'html2pdf.js' {
|
|
2
|
+
type Html2PdfOptions = {
|
|
3
|
+
margin?: number | [number, number, number, number]
|
|
4
|
+
filename?: string
|
|
5
|
+
image?: { type: string; quality: number }
|
|
6
|
+
html2canvas?: { scale: number; logging: boolean; dpi: number; letterRendering: boolean }
|
|
7
|
+
jsPDF?: { unit: string; format: string | number[]; orientation: string }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Html2Pdf = {
|
|
11
|
+
from(element: HTMLElement | string): Html2Pdf
|
|
12
|
+
set(options: Html2PdfOptions): Html2Pdf
|
|
13
|
+
toPdf(): Html2Pdf
|
|
14
|
+
get(type: 'pdf'): Promise<jsPDF>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const html2pdf: () => Html2Pdf
|
|
18
|
+
export = html2pdf
|
|
19
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { deepClone, postToService } from '@serenity-is/corelib'
|
|
2
2
|
import { IdevsExportOptions, IdevsExportRequest } from '../globals'
|
|
3
|
+
import html2pdf from 'html2pdf.js'
|
|
4
|
+
import { jsPDF } from 'jspdf'
|
|
3
5
|
|
|
4
6
|
export function doExportPdf(options: IdevsExportOptions): void {
|
|
5
7
|
const grid = options.grid
|
|
@@ -27,3 +29,35 @@ export function doExportPdf(options: IdevsExportOptions): void {
|
|
|
27
29
|
|
|
28
30
|
postToService({ service: options.service, request: request, target: '_blank' })
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
export type generatePdfOption = {
|
|
34
|
+
unit?: string
|
|
35
|
+
format?: string
|
|
36
|
+
orientation?: string
|
|
37
|
+
margin?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function generatePdf(content: string, option?: generatePdfOption): void {
|
|
41
|
+
const margin = option?.margin ?? 10
|
|
42
|
+
const unit = option?.unit ?? 'mm'
|
|
43
|
+
const format = option?.format ?? 'a4'
|
|
44
|
+
const orientation = option?.orientation ?? 'portrait'
|
|
45
|
+
if (content) {
|
|
46
|
+
html2pdf()
|
|
47
|
+
.from(content)
|
|
48
|
+
.set({
|
|
49
|
+
margin: margin,
|
|
50
|
+
filename: 'filename.pdf',
|
|
51
|
+
image: { type: 'jpeg', quality: 0.98 },
|
|
52
|
+
html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true },
|
|
53
|
+
jsPDF: { unit: unit, format: format, orientation: orientation },
|
|
54
|
+
})
|
|
55
|
+
.toPdf()
|
|
56
|
+
.get('pdf')
|
|
57
|
+
.then((pdf: jsPDF) => {
|
|
58
|
+
const blob = pdf.output('blob')
|
|
59
|
+
const url = URL.createObjectURL(blob)
|
|
60
|
+
window.open(url, '_blank')
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
}
|