fromURL static method

Future<PDFDocument> fromURL(
  1. String url, {
  2. Map<String, String>? headers,
  3. CacheManager? cacheManager,
  4. dynamic clearPreviewCache = true,
})

Load a PDF File from a given URL. File is saved in cache

String url url of the pdf file Map<String,String headers headers to pass for the url CacheManager cacheManager to provide configuration for cache management Automatically clears the on-disk cache of previously rendered PDF previews unless clearPreviewCache is set to false. The option to disable it comes in handy when working with more than one document at the same time. If you do this, you are responsible for eventually clearing the cache by hand by calling PDFDocument.clearPreviewCache.

Implementation

static Future<PDFDocument> fromURL(String url,
    {Map<String, String>? headers, CacheManager? cacheManager, clearPreviewCache = true}) async {
  // Download into cache
  File f = await (cacheManager ?? DefaultCacheManager())
      .getSingleFile(url, headers: headers);
  PDFDocument document = PDFDocument();
  document._filePath = f.path;
  try {
    var pageCount = await _channel.invokeMethod('getNumberOfPages',
        {'filePath': f.path, 'clearCacheDir': clearPreviewCache});
    document.count = document.count = int.parse(pageCount);
  } catch (e) {
    throw Exception('Error reading PDF!');
  }
  return document;
}