fetchPdfAsBytes method

Future<Uint8List> fetchPdfAsBytes(
  1. String url
)

Implementation

Future<Uint8List> fetchPdfAsBytes(String url) async {
  try {
    final proxyUrl =
        'https://workers-playground-tiny-snow-5cbb.munawera808.workers.dev?url=${Uri.encodeComponent(url)}';
    final response = await http.get(Uri.parse(proxyUrl));

    if (response.statusCode == 200 && response.bodyBytes.isNotEmpty) {
      return response.bodyBytes;
    } else {
      throw Exception(
          'Failed to load PDF via Worker. Status: ${response.statusCode}');
    }
  } catch (e) {
    return Uint8List(0);
  }
}