Share a Downloaded PDF
Download the remote document to an app-owned cache file with your existing file
download library, keeping the .pdf extension. Then share the local file URI on
Android or iOS. This avoids loading the complete file into JavaScript as base64.
import Share from 'react-native-share';
async function shareDownloadedPdf(filePath) {
return Share.open({
url: filePath.startsWith('file://') ? filePath : `file://${filePath}`,
type: 'application/pdf',
failOnCancel: false,
});
}
filePath must refer to an existing local file, not the remote download URL.
Handle download and sharing failures in your caller. Do not delete the file
immediately when Share.open resolves: selecting a target does not guarantee
that the receiving app has finished reading it. Use your app's cache-retention
policy to remove old files later, and keep distinct downloads in distinct paths.
Target applications decide which attachment types they accept; this recipe does not guarantee PDF support in every social app.