createDocumentFile method
Future<void>
createDocumentFile({
- required String path,
- void onException(
- dynamic error
- void onSucessWrite([
- Object? data
- DeltaAttributesOptions? deltaOptionalAttr,
- bool overrideAttributesPassedByUser = false,
- bool shouldProcessDeltas = true,
This Create the PDF document and write it to storage path
Implementation
//This implementation can throw PathNotFoundException or exceptions based in Storage capabilities
Future<void> createDocumentFile({
required String path,
void Function(dynamic error)? onException,
void Function([Object? data])? onSucessWrite,
DeltaAttributesOptions? deltaOptionalAttr,
bool overrideAttributesPassedByUser = false,
bool shouldProcessDeltas = true,
}) async {
deltaOptionalAttr ??= DeltaAttributesOptions.common();
final Converter<Delta, pw.Document> converter = PdfService(
params: params,
fonts: globalFontsFallbacks,
onRequestBoldFont: onRequestBoldFont,
onRequestBothFont: onRequestBoldItalicFont,
onRequestFallbacks: onRequestFallbackFont,
onRequestFont: onRequestFont,
customDeltaToHTMLConverter: customDeltaToHTMLConverter,
customHTMLToMarkdownConverter: customHTMLToMarkdownConverter,
onDetectAlignedParagraph: onDetectAlignedParagraph,
onDetectCommonText: onDetectCommonText,
customTheme: themeData,
blockQuoteBackgroundColor: blockQuoteBackgroundColor,
blockQuoteDividerColor: blockQuoteDividerColor,
codeBlockBackgroundColor: codeBlockBackgroundColor,
codeBlockFont: codeBlockFont,
codeBlockNumLinesTextStyle: codeBlockNumLinesTextStyle,
codeBlockTextStyle: codeBlockTextStyle,
blockQuoteTextStyle: blockQuoteTextStyle,
onDetectBlockquote: onDetectBlockquote,
onDetectCodeBlock: onDetectCodeBlock,
onDetectHeaderAlignedBlock: onDetectHeaderAlignedBlock,
onDetectHeaderBlock: onDetectHeaderBlock,
onDetectImageBlock: onDetectImageBlock,
blockQuotePaddingLeft: blockQuotePaddingLeft,
blockQuotePaddingRight: blockQuotePaddingRight,
blockQuotethicknessDividerColor: blockQuotethicknessDividerColor,
onDetectInlineRichTextStyles: onDetectInlineRichTextStyles,
onDetectInlinesMarkdown: onDetectInlinesMarkdown,
onDetectLink: onDetectLink,
onDetectList: onDetectList,
backM: !shouldProcessDeltas
? backMatterDelta
: processDelta(backMatterDelta, deltaOptionalAttr,
overrideAttributesPassedByUser),
converterOptions: convertOptions,
frontM: !shouldProcessDeltas
? frontMatterDelta
: processDelta(frontMatterDelta, deltaOptionalAttr,
overrideAttributesPassedByUser),
onRequestItalicFont: onRequestItalicFont,
customConverters: customConverters,
document: !shouldProcessDeltas
? document
: processDelta(
document, deltaOptionalAttr, overrideAttributesPassedByUser)!,
);
if (customRules != null) {
assert(customRules!.isNotEmpty,
'Cannot be passed a list of new rules empty');
final List<qpdf.Rule>? rules = customRules;
converter.customRules(rules!, clearDefaultRules: true);
}
try {
final pw.Document doc = await converter.generateDoc();
await File(path).writeAsBytes(await doc.save());
onSucessWrite?.call(path);
} catch (e) {
onException?.call(e);
debugPrint(e.toString());
if (onException == null) debugPrint(e.toString());
}
}