generatePdfFromHtmlString method

Future<String?> generatePdfFromHtmlString(
  1. String html,
  2. String outPutFile, [
  3. dynamic options
])

Generates a PDF from HTML string.

html: The HTML string to be converted to PDF. outPutFile: The path to the output file. Returns the path to the generated PDF file or null if the input is invalid or if the PDF generation fails.

Implementation

Future<String?> generatePdfFromHtmlString(String html, String outPutFile,
    [dynamic options]) async {
  if (outPutFile.isEmpty || html.isEmpty) {
    return null;
  }
  try {
    return await _channel
        .invokeMethod('generatePdfFromHtmlString', <String, dynamic>{
      'html': html,
      'outputPath': outPutFile,
      'options': options ?? {'documentTitle': 'Document'}
    });
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
    }
    return null;
  }
}