Skip to main content

PDF Creation | Cordova Document Scanner

ScanbotSdk.createPdf(args: {images: string[], pageSize: PDFPageSize})

Renders the given image files into a PDF document and stores it as a file. For each image, a separate page is generated.

Typically, the final hi-res document image files of the scanned Pages (documentImageFileUri) are used to generate the PDF file.

import ScanbotSdk, { Page } from 'cordova-plugin-scanbot-sdk';
private SDK = ScanbotSdk.promisify();public scannedPages: Page[] = ...;
// Always make sure you have a valid license on runtime via SDK.getLicenseInfo()if (!licenseCheckMethod()) { return; }
const result = await this.SDK.createPdf({  images: this.scannedPages.map(p => p.documentImageFileUri),  pageSize: 'FIXED_A4'});
// use the PDF file URI from result, e.g.:await uploadPdf(result.pdfFileUri);

Input args:

  • images: Input images as an array of file URIs in proper order (image element 1 => page 1, etc).
  • pageSize: PDF page size enum value to specify the output page size. See below.

Result:

  • pdfFileUri: File URI of the PDF result file ('file:///...').

Supported PDF Page Sizes#

  • A4: The page has the aspect ratio of the image, but is fitted into A4 size. Whether portrait or landscape depends on the image's aspect ratio.
  • FIXED_A4: The page has A4 size. The image is fitted and centered within the page. Whether portrait or landscape depends on the image's aspect ratio.
  • US_LETTER: The page has the aspect ratio of the image, but is fitted into US letter size. Whether portrait or landscape depends on the image's aspect ratio.
  • FIXED_US_LETTER: The page has US letter size. The image is fitted and centered within the page. Whether portrait or landscape depends on the image's aspect ratio.
  • AUTO: For each page the best matching format (A4 or US letter) is used. Whether portrait or landscape depends on the image's aspect ratio.
  • AUTO_LOCALE: Each page of the result PDF will be of US letter or A4 size depending on the current locale. Whether portrait or landscape depends on the image's aspect ratio.
  • FROM_IMAGE: Each page is as large as its image at 72 dpi.
PDF with OCR

If you need to generate a searchable PDF file with a text layer, please refer to the "OCR" section.