TF-2520 Convert email object to html to perform print on browser
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/domain/exceptions/download_file_exception.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FileUtils {
|
||||
@@ -111,4 +114,11 @@ class FileUtils {
|
||||
logError('FileUtils::removeFolder():EXCEPTION: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> convertImageAssetToBase64(String assetImage) async {
|
||||
ByteData bytes = await rootBundle.load(assetImage);
|
||||
final buffer = bytes.buffer;
|
||||
final base64Data = base64Encode(Uint8List.view(buffer));
|
||||
return base64Data;
|
||||
}
|
||||
}
|
||||
@@ -91,4 +91,13 @@ class HtmlInteraction {
|
||||
});
|
||||
</script>
|
||||
''';
|
||||
|
||||
static const String scriptHandleInvokePrinterOnBrowser = '''
|
||||
<script type="text/javascript">
|
||||
document.body.onload= function() {
|
||||
document.body.offsetHeight;
|
||||
window.print();
|
||||
};
|
||||
</script>
|
||||
''';
|
||||
}
|
||||
@@ -21,14 +21,47 @@ class HtmlTemplate {
|
||||
}
|
||||
''';
|
||||
|
||||
static const String sampleHtmlDocument = '''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
</head>
|
||||
<body</body>
|
||||
</html>
|
||||
static const String printDocumentCssStyle = '''
|
||||
<style>
|
||||
body,td,div,p,a,input {
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
body, td {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
a:link, a:active {
|
||||
color: #1155CC;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
a:visited{
|
||||
color: #6611CC;
|
||||
}
|
||||
|
||||
img {
|
||||
border: 0px
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: pre;
|
||||
white-space: -moz-pre-wrap;
|
||||
white-space: -o-pre-wrap;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
max-width: 800px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.logo {
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
''';
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/presentation/extensions/html_extension.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
class HtmlUtils {
|
||||
static String customCssStyleHtmlEditor({TextDirection direction = TextDirection.ltr}) {
|
||||
@@ -94,4 +96,31 @@ class HtmlUtils {
|
||||
</html>
|
||||
''';
|
||||
}
|
||||
|
||||
static String createTemplateHtmlDocument({String? title}) {
|
||||
return '''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
${title != null ? '<title>$title</title>' : ''}
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
''';
|
||||
}
|
||||
|
||||
static String generateSVGImageData(String base64Data) => 'data:image/svg+xml;base64,$base64Data';
|
||||
|
||||
static void openNewTabHtmlDocument(String htmlDocument) {
|
||||
final blob = html.Blob([htmlDocument], Constant.textHtmlMimeType);
|
||||
|
||||
final url = html.Url.createObjectUrlFromBlob(blob);
|
||||
|
||||
html.window.open(url, '_blank');
|
||||
|
||||
html.Url.revokeObjectUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
+195
-346
@@ -2,319 +2,166 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/data/model/print_attachment.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:htmltopdfwidgets/htmltopdfwidgets.dart' as pw;
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:core/utils/html/html_interaction.dart';
|
||||
import 'package:core/utils/html/html_template.dart';
|
||||
import 'package:core/utils/html/html_utils.dart';
|
||||
import 'package:html/dom.dart';
|
||||
import 'package:html/parser.dart';
|
||||
|
||||
class PrintUtils {
|
||||
final pw.HTMLToPdf _htmlToPdf;
|
||||
final ImagePaths _imagePaths;
|
||||
final FileUtils _fileUtils;
|
||||
|
||||
PrintUtils(this._htmlToPdf, this._imagePaths);
|
||||
PrintUtils(this._imagePaths, this._fileUtils);
|
||||
|
||||
Future<pw.Widget> _createEmailContentWidget(String htmlDocument) async {
|
||||
try {
|
||||
final List<pw.Widget> bodyWidgets = await _htmlToPdf.convert(htmlDocument);
|
||||
|
||||
return pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
...bodyWidgets
|
||||
]
|
||||
);
|
||||
} catch (e) {
|
||||
logError('PrintUtils::_createEmailContentWidget: Exception: $e');
|
||||
return pw.Text(htmlDocument);
|
||||
}
|
||||
}
|
||||
|
||||
List<pw.Widget> _createBodyWidgets({
|
||||
required pw.Context context,
|
||||
required String logoAppSvg,
|
||||
Future<Element> _createUserInformationElement({
|
||||
required String appName,
|
||||
required String userName,
|
||||
required String title,
|
||||
required String htmlDocument,
|
||||
}) async {
|
||||
final logoBase64Data = await _fileUtils.convertImageAssetToBase64(_imagePaths.icTMailLogo);
|
||||
|
||||
return Element.html('''
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tbody>
|
||||
<tr height="14px">
|
||||
<td width="40"><img src="${HtmlUtils.generateSVGImageData(logoBase64Data)}" width="40" height="40" class="logo" /></td>
|
||||
<td style="padding-left: 10px;font-size: 20px;color: #000;"><b>$appName</b></td>
|
||||
<td align="right" style="color: #777;">
|
||||
<b>$userName</b>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
''');
|
||||
}
|
||||
|
||||
Element get dividerElement => Element.html('<hr />');
|
||||
|
||||
Element _createSubjectElement(String subject) {
|
||||
return Element.html('''
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<font size="+1"><b>$subject</b></font><br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
''');
|
||||
}
|
||||
|
||||
Element _createSenderElement({
|
||||
required String senderName,
|
||||
required String senderEmailAddress,
|
||||
required String dateTime,
|
||||
}) {
|
||||
return Element.html('''
|
||||
<tr>
|
||||
<td>
|
||||
<font size="-1"><b>$senderName </b><$senderEmailAddress></font>
|
||||
</td>
|
||||
<td align="right"><font size="-1">$dateTime</font></td>
|
||||
</tr>
|
||||
''');
|
||||
}
|
||||
|
||||
String _createRecipientHtmlTag(String prefix, String emailAddress) {
|
||||
Element element = Element.html('<div class="${prefix.toLowerCase()}"></div>');
|
||||
element.text = '$prefix: $emailAddress';
|
||||
return element.outerHtml;
|
||||
}
|
||||
|
||||
Element _createRecipientsElement({
|
||||
required String toPrefix,
|
||||
required String ccPrefix,
|
||||
required String bccPrefix,
|
||||
required String replyToPrefix,
|
||||
required String titleAttachment,
|
||||
required pw.Widget contentWidget,
|
||||
String? toAddress,
|
||||
String? ccAddress,
|
||||
String? bccAddress,
|
||||
String? replyToAddress,
|
||||
List<PrintAttachment>? listAttachment,
|
||||
}) {
|
||||
return [
|
||||
pw.Container(
|
||||
padding: const pw.EdgeInsets.symmetric(horizontal: 32),
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_createUserInformationRow(
|
||||
context: context,
|
||||
logoAppSvg: logoAppSvg,
|
||||
appName: appName,
|
||||
userName: userName
|
||||
),
|
||||
_createPageDivider(),
|
||||
if (title.isNotEmpty)
|
||||
...[
|
||||
_createTitleRow(
|
||||
context: context,
|
||||
title: title
|
||||
),
|
||||
_createPageDivider(),
|
||||
],
|
||||
pw.SizedBox(height: 12),
|
||||
pw.Row(
|
||||
children: [
|
||||
pw.Expanded(
|
||||
child: _createSenderWidget(
|
||||
context: context,
|
||||
name: senderName,
|
||||
emailAddress: senderEmailAddress
|
||||
)
|
||||
),
|
||||
_createDateTimeWidget(
|
||||
context: context,
|
||||
dateTime: dateTime
|
||||
)
|
||||
]
|
||||
),
|
||||
if (replyToAddress?.isNotEmpty == true)
|
||||
_createRecipientRow(
|
||||
prefix: replyToPrefix,
|
||||
emailAddress: replyToAddress!
|
||||
),
|
||||
if (toAddress?.isNotEmpty == true)
|
||||
_createRecipientRow(
|
||||
prefix: toPrefix,
|
||||
emailAddress: toAddress!
|
||||
),
|
||||
if (ccAddress?.isNotEmpty == true)
|
||||
_createRecipientRow(
|
||||
prefix: ccPrefix,
|
||||
emailAddress: ccAddress!
|
||||
),
|
||||
if (bccAddress?.isNotEmpty == true)
|
||||
_createRecipientRow(
|
||||
prefix: bccPrefix,
|
||||
emailAddress: bccAddress!
|
||||
),
|
||||
pw.Padding(
|
||||
padding: const pw.EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 24),
|
||||
child: contentWidget
|
||||
),
|
||||
if (listAttachment?.isNotEmpty == true)
|
||||
...[
|
||||
_createPageDivider(),
|
||||
pw.SizedBox(height: 12),
|
||||
_createAttachmentTitle(
|
||||
context: context,
|
||||
title: titleAttachment,
|
||||
totalAttachments: listAttachment!.length
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
...listAttachment.map((attachment) => _createAttachmentRow(
|
||||
context: context,
|
||||
attachment: attachment
|
||||
))
|
||||
]
|
||||
]
|
||||
)
|
||||
)
|
||||
];
|
||||
return Element.html('''
|
||||
<tr>
|
||||
<td colspan="2" style="padding-bottom: 4px;" class="recipient">
|
||||
${replyToAddress?.isNotEmpty == true ? _createRecipientHtmlTag(replyToPrefix, replyToAddress!) : ''}
|
||||
${toAddress?.isNotEmpty == true ? _createRecipientHtmlTag(toPrefix, toAddress!) : ''}
|
||||
${ccAddress?.isNotEmpty == true ? _createRecipientHtmlTag(ccPrefix, ccAddress!) : ''}
|
||||
${bccAddress?.isNotEmpty == true ? _createRecipientHtmlTag(bccPrefix, bccAddress!) : ''}
|
||||
</td>
|
||||
</tr>
|
||||
''');
|
||||
}
|
||||
|
||||
pw.Widget _createPageDivider() {
|
||||
return pw.Padding(
|
||||
padding: const pw.EdgeInsets.only(top: 12),
|
||||
child: pw.Divider()
|
||||
);
|
||||
Element _createEmailContentElement(String emailContent) {
|
||||
return Element.html('''
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<table width="100%" cellpadding="12" cellspacing="0" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>$emailContent</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
''');
|
||||
}
|
||||
|
||||
pw.Widget _createPageHeader({
|
||||
required pw.Context context,
|
||||
required String appName,
|
||||
required String title,
|
||||
required String locale,
|
||||
String _createTitleAttachmentHtmlTag({
|
||||
required int countAttachments,
|
||||
required String titleAttachment
|
||||
}) {
|
||||
final currentTime = DateFormat('MM/dd/yyyy, h:mm a', locale).format(DateTime.now());
|
||||
return pw.Padding(
|
||||
padding: const pw.EdgeInsets.all(20),
|
||||
child: pw.Row(
|
||||
children: [
|
||||
pw.Text(
|
||||
currentTime,
|
||||
style: pw.Theme.of(context).defaultTextStyle.copyWith(
|
||||
fontSize: 8,
|
||||
color: pw.PdfColor.fromInt(AppColor.colorTextBody.value)
|
||||
)
|
||||
),
|
||||
pw.SizedBox(width: 16),
|
||||
pw.Expanded(
|
||||
child: pw.Text(
|
||||
'$appName - $title',
|
||||
textAlign: pw.TextAlign.center,
|
||||
maxLines: 1,
|
||||
style: pw.Theme.of(context).defaultTextStyle.copyWith(
|
||||
fontSize: 8,
|
||||
color: pw.PdfColor.fromInt(AppColor.colorTextBody.value)
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
);
|
||||
return '<tr><td colspan="2"><b style="padding-left:3">$countAttachments $titleAttachment</b></td></tr>';
|
||||
}
|
||||
|
||||
pw.Widget _createUserInformationRow({
|
||||
required pw.Context context,
|
||||
required String logoAppSvg,
|
||||
String _createAttachmentHtmlTag(PrintAttachment printAttachment) {
|
||||
return '''
|
||||
<tr>
|
||||
<td>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<a target="_blank" href="">
|
||||
<img width="16" height="16" src="${HtmlUtils.generateSVGImageData(printAttachment.iconBase64Data)}" />
|
||||
</a>
|
||||
</td>
|
||||
<td width="7"></td>
|
||||
<td>
|
||||
<b>${printAttachment.name}</b><br />
|
||||
${printAttachment.size}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
''';
|
||||
}
|
||||
|
||||
Element _createAttachmentsElement({
|
||||
required String titleAttachment,
|
||||
required List<PrintAttachment> listAttachment
|
||||
}) {
|
||||
return Element.html('''
|
||||
<table class="attachments" cellspacing="0" cellpadding="5" border="0">
|
||||
<tbody>
|
||||
${_createTitleAttachmentHtmlTag(countAttachments: listAttachment.length, titleAttachment: titleAttachment)}
|
||||
${listAttachment.map((printAttachment) => _createAttachmentHtmlTag(printAttachment)).toList().join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> printEmail({
|
||||
required String appName,
|
||||
required String userName,
|
||||
}) {
|
||||
return pw.Row(
|
||||
children: [
|
||||
pw.SvgImage(
|
||||
svg: logoAppSvg,
|
||||
width: 32,
|
||||
height: 32
|
||||
),
|
||||
pw.SizedBox(width: 12),
|
||||
pw.Text(
|
||||
appName,
|
||||
style: pw.Theme.of(context).header0
|
||||
),
|
||||
pw.Spacer(),
|
||||
pw.SizedBox(width: 12),
|
||||
pw.Text(
|
||||
userName,
|
||||
style: pw.Theme.of(context).header4
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createTitleRow({
|
||||
required pw.Context context,
|
||||
required String title,
|
||||
}) {
|
||||
return pw.Padding(
|
||||
padding: const pw.EdgeInsets.only(top: 12),
|
||||
child: pw.Text(
|
||||
title,
|
||||
style: pw.Theme.of(context).header3
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createSenderWidget({
|
||||
required pw.Context context,
|
||||
required String name,
|
||||
required String emailAddress,
|
||||
}) {
|
||||
return pw.Row(
|
||||
children: [
|
||||
if (name.isNotEmpty)
|
||||
pw.Padding(
|
||||
padding: const pw.EdgeInsetsDirectional.only(end: 4),
|
||||
child: pw.Text(
|
||||
name,
|
||||
style: pw.Theme.of(context).header4
|
||||
)
|
||||
),
|
||||
pw.Text('<$emailAddress>')
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createDateTimeWidget({
|
||||
required pw.Context context,
|
||||
required String dateTime,
|
||||
}) {
|
||||
return pw.Text(
|
||||
dateTime,
|
||||
style: pw.Theme.of(context).defaultTextStyle.copyWith(
|
||||
fontSize: 10,
|
||||
color: pw.PdfColor.fromInt(AppColor.colorTextBody.value)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createRecipientRow({
|
||||
required String prefix,
|
||||
required String emailAddress,
|
||||
}) {
|
||||
return pw.Row(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
pw.Text('$prefix:'),
|
||||
pw.SizedBox(width: 4),
|
||||
pw.Expanded(child: pw.Text(emailAddress))
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createAttachmentTitle({
|
||||
required pw.Context context,
|
||||
required String title,
|
||||
required int totalAttachments,
|
||||
}) {
|
||||
return pw.Text(
|
||||
'$totalAttachments $title',
|
||||
style: pw.Theme.of(context).header4
|
||||
);
|
||||
}
|
||||
|
||||
pw.Widget _createAttachmentRow({
|
||||
required pw.Context context,
|
||||
required PrintAttachment attachment,
|
||||
}) {
|
||||
return pw.Padding(
|
||||
padding: const pw.EdgeInsets.only(top: 8),
|
||||
child: pw.Row(
|
||||
children: [
|
||||
pw.SvgImage(
|
||||
svg: attachment.iconSvg,
|
||||
width: 24,
|
||||
height: 24
|
||||
),
|
||||
pw.SizedBox(width: 8),
|
||||
pw.Expanded(
|
||||
child: pw.Column(
|
||||
mainAxisSize: pw.MainAxisSize.min,
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
pw.Text(
|
||||
attachment.name,
|
||||
style: pw.Theme.of(context).header4
|
||||
),
|
||||
pw.Text(attachment.size)
|
||||
]
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> printEmailToPDF({
|
||||
required String appName,
|
||||
required String userName,
|
||||
required String title,
|
||||
required String subject,
|
||||
required String emailContent,
|
||||
required String senderName,
|
||||
required String senderEmailAddress,
|
||||
@@ -331,69 +178,71 @@ class PrintUtils {
|
||||
String? replyToAddress,
|
||||
List<PrintAttachment>? listAttachment,
|
||||
}) async {
|
||||
return await Printing.layoutPdf(onLayout: (pw.PdfPageFormat format) async {
|
||||
final googleInterRegularFont = await PdfGoogleFonts.interRegular();
|
||||
final googleInterBoldFont = await PdfGoogleFonts.interBold();
|
||||
final logoAppSvg = await rootBundle.loadString(_imagePaths.icTMailLogo);
|
||||
final contentWidget = await _createEmailContentWidget(emailContent);
|
||||
Document document = parse(HtmlUtils.createTemplateHtmlDocument(title: '$appName - $subject'));
|
||||
|
||||
final pdfDocument = pw.Document();
|
||||
Element bodyContainerElement = Element.html('<div class="body-container"></div>');
|
||||
Element mainContentElement = Element.html('<div class="main-content"></div>');
|
||||
Element messageElement = Element.html('<table width="100%" cellpadding="0" cellspacing="0" border="0" class="message"></table>');
|
||||
Element messageBodyElement = Element.html('<tbody></tbody>');
|
||||
|
||||
pdfDocument.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: pw.PdfPageFormat.standard,
|
||||
orientation: pw.PageOrientation.portrait,
|
||||
theme: pw.ThemeData(
|
||||
defaultTextStyle: pw.TextStyle(
|
||||
font: googleInterRegularFont,
|
||||
fontSize: 12,
|
||||
color: pw.PdfColors.black
|
||||
),
|
||||
header3: pw.TextStyle(
|
||||
font: googleInterBoldFont,
|
||||
fontSize: 14,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: pw.PdfColors.black
|
||||
),
|
||||
header4: pw.TextStyle(
|
||||
font: googleInterBoldFont,
|
||||
fontSize: 12,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: pw.PdfColors.black
|
||||
),
|
||||
),
|
||||
margin: pw.EdgeInsets.zero,
|
||||
build: (context) => _createBodyWidgets(
|
||||
context: context,
|
||||
contentWidget: contentWidget,
|
||||
logoAppSvg: logoAppSvg,
|
||||
appName: appName,
|
||||
userName: userName,
|
||||
title: title,
|
||||
htmlDocument: emailContent,
|
||||
senderName: senderName,
|
||||
senderEmailAddress: senderEmailAddress,
|
||||
dateTime: dateTime,
|
||||
toPrefix: toPrefix,
|
||||
ccPrefix: ccPrefix,
|
||||
bccPrefix: toPrefix,
|
||||
replyToPrefix: replyToPrefix,
|
||||
toAddress: toAddress,
|
||||
ccAddress: ccAddress,
|
||||
bccAddress: bccAddress,
|
||||
replyToAddress: replyToAddress,
|
||||
titleAttachment: titleAttachment,
|
||||
listAttachment: listAttachment
|
||||
),
|
||||
header: (context) => _createPageHeader(
|
||||
context: context,
|
||||
appName: appName,
|
||||
title: title,
|
||||
locale: locale,
|
||||
),
|
||||
)
|
||||
);
|
||||
return await pdfDocument.save();
|
||||
});
|
||||
Element userInfoElement = await _createUserInformationElement(
|
||||
appName: appName,
|
||||
userName: userName);
|
||||
|
||||
Element subjectElement = _createSubjectElement(subject);
|
||||
|
||||
Element senderElement = _createSenderElement(
|
||||
senderName: senderName,
|
||||
senderEmailAddress: senderEmailAddress,
|
||||
dateTime: dateTime);
|
||||
|
||||
Element recipientsElement = _createRecipientsElement(
|
||||
toPrefix: toPrefix,
|
||||
ccPrefix: ccPrefix,
|
||||
bccPrefix: bccPrefix,
|
||||
replyToPrefix: replyToPrefix,
|
||||
toAddress: toAddress,
|
||||
ccAddress: ccAddress,
|
||||
bccAddress: bccAddress,
|
||||
replyToAddress: replyToAddress,
|
||||
);
|
||||
|
||||
Element emailContentElement = _createEmailContentElement(emailContent);
|
||||
|
||||
bodyContainerElement.append(userInfoElement);
|
||||
bodyContainerElement.append(dividerElement);
|
||||
|
||||
mainContentElement.append(subjectElement);
|
||||
mainContentElement.append(dividerElement);
|
||||
|
||||
messageBodyElement.append(senderElement);
|
||||
messageBodyElement.append(recipientsElement);
|
||||
messageBodyElement.append(emailContentElement);
|
||||
|
||||
messageElement.append(messageBodyElement);
|
||||
|
||||
mainContentElement.append(messageElement);
|
||||
|
||||
if (listAttachment?.isNotEmpty == true) {
|
||||
Element attachmentsElement = _createAttachmentsElement(
|
||||
titleAttachment: titleAttachment,
|
||||
listAttachment: listAttachment!);
|
||||
mainContentElement.append(dividerElement);
|
||||
mainContentElement.append(attachmentsElement);
|
||||
}
|
||||
|
||||
bodyContainerElement.append(mainContentElement);
|
||||
|
||||
document.body?.append(bodyContainerElement);
|
||||
|
||||
Element scriptElement = Element.html(HtmlInteraction.scriptHandleInvokePrinterOnBrowser);
|
||||
document.body?.append(scriptElement);
|
||||
|
||||
Element styleElement = Element.html(HtmlTemplate.printDocumentCssStyle);
|
||||
document.head?.append(styleElement);
|
||||
|
||||
final htmlDocument = document.outerHtml;
|
||||
|
||||
HtmlUtils.openNewTabHtmlDocument(htmlDocument);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user