fromURL static method

Future<PDFDoc> fromURL(
  1. String url, {
  2. String password = "",
})

Creates a PDFDoc object with a URL. Optionally, takes a password for encrypted PDF documents. It downloads the PDF file located in the given URL and saves it in the app's temporary directory.

Implementation

static Future<PDFDoc> fromURL(String url, {String password = ""}) async {
  File file;
  try {
    final String tempDirPath = (await getTemporaryDirectory()).path;

    final String filePath = join(
      tempDirPath,
      _tempDirName,
      "${url.split("/").last.split(".").first}.pdf",
    );

    file = File(filePath);
    file.createSync(recursive: true);
    file.writeAsBytesSync(
      (await ClientProvider().client.get(Uri.parse(url))).bodyBytes,
    );
  } on Exception catch (e) {
    return Future.error(e);
  }
  return await fromFile(file, password: password);
}