1

I am making a website that can modify pdf files , and I was trying to be able to rotate a page or multiple pages but couldn't find how to do that in their docs .


 const pdfDoc = await loadSingleFile(inputFiles[0]) // An input pdf file

 const rotatedPdf = await PDFDocument.create();  // Intitialize the rotated pdf file

 const pageToRotate = pdfDoc.getPages()[pageIndex]
    

  // Not sure what to write here


 const pdfDataString = await rotatedPdf.saveAsBase64({ dataUri: true }); // here generate string for further use
K J
  • 8,045
  • 3
  • 14
  • 36
Chakib Salah
  • 499
  • 1
  • 10

1 Answers1

2

I was able solve this following a comment on my question that suggested using these two functions

https://pdf-lib.js.org/docs/api/classes/pdfpage#getrotation to get the current page rotation degree.

https://pdf-lib.js.org/docs/api/classes/pdfpage#setrotation to rotate a page.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Chakib Salah
  • 499
  • 1
  • 10