Image to PDF in React Native

PSPDFKit for React Native enables you to create a PDF document from a single image or a series of images. You can provide configuration options and a name for the new PDF document:

const configuration = {
    name: 'newImages',
    images: [imageObject],
    override: true
};
try {
    const { fileURL } = await Processor.newFromImages(configuration);
} catch (error) {
    console.log(error);
}

Due to property limitations between the React Native and the native iOS/Android layer, the image blob cannot be directly passed to native code. Instead, pass the path to the image, which can be loaded directly from the local path on the iOS/Android side. To do so, use the resolveAssetSource function from the react-native package. This returns an object with a uri property that you can use to download the image from the web or from local storage:

const downloadImage = async (imageObject, extension, onLoad) => {
   return await RNFetchBlob.config({
     fileCache: true,
     appendExt: extension
   })
     .fetch('GET', imageObject.uri)
     .catch(error => console.log(error));
 };

For more information on customizing your document, see the list of all configuration options you can use with Processor.