Skip to content
ComPDF
DemoAPI ReferenceFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Run Project

After installing from NPM or GitHub, replace App.tsx with the following code.

Make sure to follow the above steps to copy the sample document into your Android or iOS project.

Here is the sample code for App.tsx:

tsx
import React, { Component } from 'react';
import { SafeAreaView } from 'react-native';
import { ComPDFKit, CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
import { Platform } from 'react-native';

type Props = {};

export default class App extends Component<Props> {

  constructor(props: Props) {
    super(props)
    this.initialize()
  }

  async initialize() {
    var result = await ComPDFKit.initWithPath(Platform.OS == "android" ? "assets://license_key_rn.xml" : "license_key_rn.xml")
    console.log("ComPDFRN", "init_:", result)
  }

  samplePDF = Platform.OS === 'android'
  ? 'file:///android_asset/PDF_Document.pdf'
  : 'PDF_Document.pdf';


  render() {
    return (
      <CPDFReaderView
        document={this.samplePDF}
        configuration={ComPDFKit.getDefaultConfig({})}
        style={{ flex: 1 }}
        />
    );
  }
}
  • (Android) For local storage file path:
tsx
document = '/storage/emulated/0/Download/PDF_document.pdf'
  • (Android) For content Uri:
tsx
document = 'content://...'
  • (Android) For assets path:
tsx
document = "file:///android_asset/..."
  • (iOS) For app bundle file path:
tsx
document = "document.pdf"
  • (iOS) for URL path:
tsx
document = "file://xxxx/document.pdf"

The app is now ready to launch! Go back to the terminal app and run:

shell
npx react-native run-android
npx react-native run-ios