PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
This guide explains how to integrate @compdfkit_pdf_sdk/react_native into an Expo project.
ComPDFKit depends on native iOS and Android code, so it is not supported in Expo Go. Use a development build, expo run, or EAS Build instead.
The Expo config plugin included in the package updates the iOS Podfile during expo prebuild. Manual changes to ios/Podfile are not required.
Ensure that your environment is ready for native Expo builds:
Run the following commands:
npx create-expo-app compdfkit_expo
cd compdfkit_expoThen install the Expo project dependencies:
npm install
# or
yarn installRun:
yarn add @compdfkit_pdf_sdk/react_nativeUpdate app.json as follows:
{
"expo": {
"plugins": ["@compdfkit_pdf_sdk/react_native"]
}
}Also make sure your project uses the correct iOS bundleIdentifier and Android package values. ComPDFKit licenses are bound to those identifiers.
If your Expo project also needs custom native build settings, such as compileSdkVersion, minSdkVersion, or deploymentTarget, you can additionally install and configure expo-build-properties. It is optional and is not required for the ComPDFKit plugin itself.
Run:
CI=1 npx expo prebuild --cleanThis command generates the ios and android folders and applies the ComPDFKit plugin.
After prebuild completes, open ios/Podfile.
You should see a generated block similar to the following under use_expo_modules!:
# @generated begin compdfkit-react-native-ios-pods
pod 'ComPDFKit', :podspec => 'https://file.compdf.com/cocoapods/ios/compdfkit_pdf_sdk/3.0.0/ComPDFKit.podspec'
pod 'ComPDFKit_Tools', :podspec => 'https://file.compdf.com/cocoapods/ios/compdfkit_pdf_sdk/3.0.0/ComPDFKit_Tools.podspec'
# @generated end compdfkit-react-native-ios-podsIf this block is present, the plugin is working correctly and no manual Podfile changes are required.
Run:
eas build:configureIf Expo prompts you to sign in, complete that step first.
If you choose All, Expo creates an eas.json file similar to the following:
{
"cli": {
"version": ">= 5.4.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}At this stage, the Expo plugin only handles iOS Podfile integration. Android permissions still need to be added manually after prebuild.
Open android/app/src/main/AndroidManifest.xml and add the following:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<application
android:requestLegacyExternalStorage="true"
...>
</application>For this example, copy a PDF named PDF_Document.pdf into the following locations after prebuild:
android/app/src/main/assets/PDF_Document.pdfThis example uses native bundled file paths. If you run expo prebuild --clean again later, verify whether the sample file needs to be copied again.
Replace the contents of index.tsx with the following example:
import { Platform, SafeAreaView } from 'react-native';
import { Component } from 'react';
import { ComPDFKit, CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
const androidLicense = 'android license';
const iosLicense = 'ios license';
type Props = {};
export default class HomeScreen extends Component<Props> {
constructor(props: Props) {
super(props);
this.initialize();
}
async initialize() {
const result = await ComPDFKit.init_(
Platform.OS === 'android' ? androidLicense : iosLicense
);
console.log('ComPDFKitRN', 'init_:', result);
}
samplePDF =
Platform.OS === 'android'
? 'file:///android_asset/PDF_Document.pdf'
: 'PDF_Document.pdf';
render() {
return (
<SafeAreaView style={{ flex: 1 }}>
<CPDFReaderView
document={this.samplePDF}
configuration={ComPDFKit.getDefaultConfig({})}
style={{ flex: 1 }}
/>
</SafeAreaView>
);
}
}Before running the app, replace androidLicense and iosLicense with your actual ComPDFKit license values.
Trial licenses for the ComPDFKit React Native SDK are available in the GitHub example project or by contacting the ComPDFKit sales team.
Run:
npx expo run:androidOr:
npx expo run:iosRun:
eas build --platform iosOr:
eas build --platform androidUse these commands when you want Expo to build the native application in the cloud with the same plugin configuration defined in app.json.
This behavior is expected. ComPDFKit requires native modules, so use a development build, expo run, or EAS Build.
Ensure that @compdfkit_pdf_sdk/react_native is listed in expo.plugins, then run:
CI=1 npx expo prebuild --cleanIf you run expo prebuild --clean, Expo regenerates the native projects. Copy the sample PDF into the generated native project again.