refactor(export): move PDF table template to shared package

This commit is contained in:
Ahmed Bouhuolia
2025-12-29 23:54:43 +02:00
parent 350d229e98
commit 339289be9f
4 changed files with 143 additions and 12 deletions

View File

@@ -1,14 +1,13 @@
import { Injectable } from '@nestjs/common';
import { ChromiumlyTenancy } from '../ChromiumlyTenancy/ChromiumlyTenancy.service';
import { TemplateInjectable } from '../TemplateInjectable/TemplateInjectable.service';
import { renderExportResourceTableTemplateHtml } from '@bigcapital/pdf-templates';
import { mapPdfRows } from './utils';
@Injectable()
export class ExportPdf {
constructor(
private readonly templateInjectable: TemplateInjectable,
private readonly chromiumlyTenancy: ChromiumlyTenancy,
) {}
) { }
/**
* Generates the pdf table sheet for the given data and columns.
@@ -19,21 +18,18 @@ export class ExportPdf {
* @returns
*/
public async pdf(
columns: { accessor: string },
columns: { accessor: string; name?: string; style?: string; group?: string }[],
data: Record<string, any>,
sheetTitle: string = '',
sheetDescription: string = ''
) {
const rows = mapPdfRows(columns, data);
const htmlContent = await this.templateInjectable.render(
'modules/export-resource-table',
{
table: { rows, columns },
sheetTitle,
sheetDescription,
}
);
const htmlContent = renderExportResourceTableTemplateHtml({
table: { rows, columns },
sheetTitle,
sheetDescription,
});
// Convert the HTML content to PDF
return this.chromiumlyTenancy.convertHtmlContent(htmlContent, {
margins: { top: 0.2, bottom: 0.2, left: 0.2, right: 0.2 },