2023-10-16 16:28:12 +00:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
import * as paths from './paths.js';
|
|
|
|
import * as helpers from './helpers.js';
|
|
|
|
|
|
|
|
export interface IPdfServiceConstructorOptions {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a pdf service for generating pdfs
|
|
|
|
*/
|
|
|
|
export class PdfService {
|
2024-02-16 18:18:20 +00:00
|
|
|
// STATIC
|
|
|
|
public static async createAndStart(optionsArg: IPdfServiceConstructorOptions) {
|
|
|
|
const pdfService = new PdfService(optionsArg);
|
|
|
|
await pdfService.start();
|
|
|
|
return pdfService;
|
|
|
|
}
|
|
|
|
|
2023-10-16 16:28:12 +00:00
|
|
|
// INSTANCE
|
|
|
|
options: IPdfServiceConstructorOptions;
|
|
|
|
|
|
|
|
public smartpdfInstance: plugins.smartpdf.SmartPdf;
|
|
|
|
|
|
|
|
constructor(optionsArg: IPdfServiceConstructorOptions) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* starts the PdfService
|
|
|
|
*/
|
|
|
|
public async start() {
|
|
|
|
this.smartpdfInstance = new plugins.smartpdf.SmartPdf();
|
|
|
|
await this.smartpdfInstance.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stops the PdfService
|
|
|
|
*/
|
|
|
|
public async stop() {
|
|
|
|
await this.smartpdfInstance.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates an letter
|
|
|
|
*/
|
|
|
|
public async createPdfFromLetterObject(letterDataArg: plugins.tsclass.business.ILetter) {
|
|
|
|
const html = `
|
|
|
|
<script type="module">
|
|
|
|
${await helpers.getBundleAsString()}
|
|
|
|
</script>
|
|
|
|
<dedocument-dedocument printMode letterData="${plugins.smartjson.stringifyBase64(letterDataArg)}"></dedocument-dedocument>
|
|
|
|
`;
|
|
|
|
// console.log(html);
|
|
|
|
const pdfResult = await this.smartpdfInstance.getA4PdfResultForHtmlString(html);
|
|
|
|
return pdfResult;
|
|
|
|
}
|
|
|
|
}
|