PagesApi.import()
Inserts every page of another PDF. A page with form fields comes in flattened, as it prints: its fields do not join this document's form. Needs the edit-pages feature.
Importing is a load for the license, once the imported file has opened: under a stopped license (paused, revoked, expired, a copied or forged key) it is refused with LICENSE_REQUIRED, as opening a document is.
methodImport and extractsince 1.0.0
Signature
import(bytes: Uint8Array, options?: ImportPagesOptions): Promise<number>
Parameters
| Parameter | Type | Description |
|---|---|---|
| bytes | Uint8Array | The source PDF. |
| options? | ImportPagesOptions | position ({ after } or { before }; appended when omitted), password (the source's, if it is encrypted) and invalidateSignatures. |
Returns
Promise<number> How many pages came in.
Throws
FEATURE_NOT_LICENSED— the license lacksedit-pages.LICENSE_REQUIRED— the license is stopped.FORMAT_ERROR— the imported bytes are not a PDF, or a corrupt one.PASSWORD_ERROR— the imported file needs a password, oroptions.passwordis wrong.SECURITY_ERROR— the imported file is encrypted with a security handler the SDK cannot open.INVALID_ARGUMENT— the position is not a whole number (one past the ends is clamped).PAGE_ERROR— a page could not be copied in, its form fields could not be flattened, or the page tree is nested too deeply.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document whose certification forbids it, unlessoptions.invalidateSignatures; or a progressive document still downloading.
Example
TypeScript
const other = new Uint8Array(await (await fetch('/terms.pdf')).arrayBuffer()); const added = await doc.pages.import(other); // appended at the end