Important: Rotation changes PDF identity and affects annotations

When you rotate pages, the document’s internal pdfId changes. This affects Instant JSON compatibility, so if you’re storing Instant JSON for later use, you’ll need to handle this properly.

If you store Instant JSON with pdfId:

// Remove `pdfId` before persisting to avoid PDF ID mismatch errors.
const {pdfId, ...instantJSON} = await instance.exportInstantJSON()
await saveToDatabase(instantJSON)

Annotations don’t automatically rotate

When you rotate a page, existing annotations stay at their original coordinates and orientation. The rotation operation only affects the page itself, and not the annotations on it. To make annotations match the rotated page, you need to manually update their rotation property or reposition them accordingly.

Learn more about handling pdfId with document operations.


The rotatePages operation will rotate the specified pages by the desired amount; only multiples of 90 under 360 are allowed as values.

If the page is already rotated, this will add the specified rotation, so if a page is already rotated 90 degrees and you apply a 90-degreee rotation, it’ll result in the page being rotated 180 degrees:

instance.applyOperations([
{
type: "rotatePages",
pageIndexes: [0], // Rotate page 0.
rotateBy: 90 // Rotate page 90 degrees clockwise.
}
]);

After this operation is complete, call exportPDF to get a buffer containing the data for the final PDF.

If you need to apply this operation and export in one step, you can provide the same argument you provide to applyOperations to exportPDFWithOperations to get a buffer containing the data for the final PDF.