createDocument method

Future<Document?> createDocument({
  1. DeltaAttributesOptions? deltaOptionalAttr,
  2. bool overrideAttributesPassedByUser = false,
  3. void onException(
    1. dynamic error
    )?,
  4. bool shouldProcessDeltas = true,
})

Creates the PDF document an return this one

Implementation

Future<pw.Document?> createDocument({
  DeltaAttributesOptions? deltaOptionalAttr,
  bool overrideAttributesPassedByUser = false,
  void Function(dynamic error)? onException,
  bool shouldProcessDeltas = true,
}) async {
  deltaOptionalAttr ??= DeltaAttributesOptions.common();
  final Converter<Delta, pw.Document> converter = PdfService(
    params: params,
    fonts: globalFontsFallbacks,
    onRequestBoldFont: onRequestBoldFont,
    onRequestBothFont: onRequestBoldItalicFont,
    customDeltaToHTMLConverter: customDeltaToHTMLConverter,
    customHTMLToMarkdownConverter: customHTMLToMarkdownConverter,
    customTheme: themeData,
    blockQuoteBackgroundColor: blockQuoteBackgroundColor,
    blockQuoteDividerColor: blockQuoteDividerColor,
    codeBlockBackgroundColor: codeBlockBackgroundColor,
    codeBlockFont: codeBlockFont,
    codeBlockNumLinesTextStyle: codeBlockNumLinesTextStyle,
    codeBlockTextStyle: codeBlockTextStyle,
    blockQuoteTextStyle: blockQuoteTextStyle,
    onRequestFallbacks: onRequestFallbackFont,
    onDetectAlignedParagraph: onDetectAlignedParagraph,
    onDetectCommonText: onDetectCommonText,
    onDetectBlockquote: onDetectBlockquote,
    onDetectCodeBlock: onDetectCodeBlock,
    blockQuotePaddingLeft: blockQuotePaddingLeft,
    blockQuotePaddingRight: blockQuotePaddingRight,
    blockQuotethicknessDividerColor: blockQuotethicknessDividerColor,
    onDetectHeaderAlignedBlock: onDetectHeaderAlignedBlock,
    onDetectHeaderBlock: onDetectHeaderBlock,
    onDetectImageBlock: onDetectImageBlock,
    onDetectInlineRichTextStyles: onDetectInlineRichTextStyles,
    onDetectInlinesMarkdown: onDetectInlinesMarkdown,
    onDetectLink: onDetectLink,
    onDetectList: onDetectList,
    onRequestFont: onRequestFont,
    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 {
    return await converter.generateDoc();
  } catch (e) {
    onException?.call(e);
    debugPrint(e.toString());
    return null;
  }
}