Open a Document From URL in Flutter PDF Viewer

14 Aug 20261 minute to read

The SfPdfViewer.network creates a widget that displays the PDF document obtained from a URL. The following code example explains the same.

@override
Widget build(BuildContext context) {
  return Scaffold(
      body: SfPdfViewer.network(
              'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf'));
}

To load a PDF from network using SfPdfViewer.network on macOS, network access must be enabled in your macOS application. In your macos/Runner/DebugProfile.entitlements file, add the following lines inside the <dict> tag to enable network access in your application:

<key>com.apple.security.network.client</key>
<true/>

Due to CORS security restrictions in a web application, some PDFs obtained from URLs might not be loaded on the SfPdfViewer web platform. Kindly refer to the Flutter forum for more information on this issue.

This issue can be resolved by configuring the CORS settings on the requested server or by disabling the security settings in chrome.dart as mentioned in the steps below:

  1. Go to flutter\bin\cache and remove a file named: flutter_tools.stamp.
  2. Go to flutter\packages\flutter_tools\lib\src\web and open the file chrome.dart.
  3. Find ’–disable-extensions’.
  4. Add ’–disable-web-security’.