Processor

Processor is a React Native Native Module implementation used to call iOS and Android methods directly.
Source:
Example
const Processor = NativeModules.RNProcessor;

Methods

(static) generateBlankPDF(configuration) → {Promise.<GeneratePDFResult>}

Used to generate a new blank PDF document.
Parameters:
Name Type Description
configuration BlankPDFConfiguration The configuration to generate a new blank PDF document.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
const configuration = {
   name: 'newDocument.pdf',
   width: 595,
   height: 842,
   override: true,
 };
const { fileURL } = await Processor.generateBlankPDF(configuration);

(static) generatePDFFromDocuments(configuration) → {Promise.<GeneratePDFResult>}

Used to generate a new PDF document from existing PDF documents.
Parameters:
Name Type Description
configuration DocumentPDFConfiguration The configuration to generate a new PDF document.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
const fileName = 'newDocument.pdf';
const { tempDir } = await Processor.getTemporaryDirectory();
const documentPath = `${tempDir}/${fileName}`;

const exampleDocument = 'PSPDFKit_Image_Example.jpg';
const exampleDocumentPath =
Platform.OS === 'ios' ? 'PDFs/' + exampleImage : 'file:///android_asset/' + exampleDocument;

// Helper method to get iOS bundlePath
let globalPath = getMainBundlePath(exampleDocumentPath.toString());

const configuration = {
    filePath: documentPath,
    name: fileName,
    documents: [
      {
        documentPath:
          Platform.OS === 'ios' ? globalPath : exampleDocumentPath,
        pageIndex: 5,
      },
      {
        documentPath:
          Platform.OS === 'ios' ? globalPath : exampleDocumentPath,
        pageIndex: 8,
      },
    ],
    override: true,
  };
const { fileURL } = await Processor.generatePDFFromDocuments(configuration);

(static) generatePDFFromHtmlString(configuration, html) → {Promise.<GeneratePDFResult>}

Used to generate a new PDF document from an HTML string.
Parameters:
Name Type Description
configuration GeneratePDFConfiguration The configuration to generate a new PDF document.
html string The HTML string from which the document should be generated.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
const fileName = 'newDocument.pdf';
const { tempDir } = await Processor.getTemporaryDirectory();
const documentPath = `${tempDir}/${fileName}`;

const htmlString = `<html lang="en"><head></head><body><h1>PDF generated from HTML</h1></body></html>`;
const configuration = {
   filePath: documentPath,
   override: true,
 };
const { fileURL } = await Processor.generatePDFFromHtmlString(configuration, htmlString);

(static) generatePDFFromHtmlURL(configuration, url) → {Promise.<GeneratePDFResult>}

Used to generate a new PDF document from an HTML URL.
Parameters:
Name Type Description
configuration GeneratePDFConfiguration The configuration to generate a new PDF document.
url string The origin URL from which the document should be generated.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
const fileName = 'newDocument.pdf';
const { tempDir } = await Processor.getTemporaryDirectory();
const documentPath = `${tempDir}/${fileName}`;
const url = `https://www.pspdfkit.com`;
const configuration = {
   documentPath: documentPath,
   override: true,
 };
const { fileURL } = await Processor.generatePDFFromHtmlURL(configuration, url);

(static) generatePDFFromImages(configuration) → {Promise.<GeneratePDFResult>}

Used to generate a new PDF document from images.
Parameters:
Name Type Description
configuration ImagePDFConfiguration The configuration to generate a new PDF document.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
export const exampleImage = 'PSPDFKit_Image_Example.jpg';
export const exampleImagePath =
Platform.OS === 'ios' ? 'PDFs/' + exampleImage : 'file:///android_asset/' + exampleImage;

// Helper method to get iOS bundlePath
let globalPath = getMainBundlePath(exampleImagePath.toString());
const configuration = {
    name: 'newDocument.pdf',
    images: [
      {
        imageUri: Platform.OS === 'ios' ? globalPath : exampleImagePath,
        position: 'center',
      },
    ],
    override: true,
  };
const { fileURL } = await Processor.generatePDFFromImages(configuration);

(static) generatePDFFromTemplate(configuration) → {Promise.<GeneratePDFResult>}

Used to generate a new PDF document from a template.
Parameters:
Name Type Description
configuration TemplatePDFConfiguration The configuration to generate a new PDF document.
Source:
Returns:
A promise containing the path to the newly generated document.
Type
Promise.<GeneratePDFResult>
Example
const configuration = {
   filePath: fileURL,
   override: true,
    templates: [
      {
        pageSize: { width: 540, height: 846 },
        backgroundColor: 'rgba(0.871, 0.188, 0.643, 0.5)',
        template: 'lines7mm',
        rotation: 90,
        pageMargins: { top: 10, left: 10, right: 10, bottom: 10 },
      },
      {
        pageSize: { width: 540, height: 846 },
        backgroundColor: 'yellow',
        template: 'dot5mm',
      },
    ],
  };
const { fileURL } = await Processor.generatePDFFromTemplate(configuration);

(static) getTemporaryDirectory() → {Promise.<any>}

A helper method to get a temporary directory where the document can be written to.
Source:
Returns:
A promise containing the path to the temporary directory that can be used for output.
Type
Promise.<any>
Example
const { fileURL } = await Processor.getTemporaryDirectory();