Putar Halaman PDF di Node.js

Contents
[ ]

Bagian ini menjelaskan cara memutar halaman dalam file PDF yang ada menggunakan Aspose.PDF for Node.js via C++.

Jika Anda ingin memutar halaman PDF, Anda dapat menggunakan AsposePdfRotateAllPages fungsi. Fungsi ini menggunakan parameter khusus ‘AsposePdfModule.Rotation’ untuk nilai rotasi. Dengan parameter ini Anda dapat mengatur berapa derajat yang perlu diputar PDF. Ada variasi: None, 90, 180, atau 270 derajat.

Silakan periksa potongan kode berikut untuk memutar halaman PDF di lingkungan Node.js.

CommonJS:

  1. Panggilan require dan impor asposepdfnodejs modul sebagai AsposePdf variabel.
  2. Tentukan nama file PDF yang akan diputar.
  3. Panggilan AsposePdf sebagai Promise dan lakukan operasi untuk memutar halaman. Terima objek jika berhasil.
  4. Panggil fungsi AsposePdfRotateAllPages.
  5. Putar semua file PDF. Rotasi diatur ke 270 derajat (on270). Jadi, jika ‘json.errorCode’ adalah 0, hasil operasi disimpan dalam “ResultRotation.pdf”. Jika parameter json.errorCode bukan 0 dan, akibatnya, muncul error di file Anda, informasi error akan berada dalam ‘json.errorText’.

  const AsposePdf = require('asposepdfnodejs');
  const pdf_file = 'Aspose.pdf';
  AsposePdf().then(AsposePdfModule => {
      /*Rotate PDF-pages and save the "ResultRotation.pdf"*/
      const json = AsposePdfModule.AsposePdfRotateAllPages(pdf_file, AsposePdfModule.Rotation.on270, "ResultRotation.pdf");
      console.log("AsposePdfRotateAllPages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
  });

ECMAScript/ES6:

  1. Impor asposepdfnodejs modul.
  2. Tentukan nama file PDF yang akan diputar.
  3. Inisialisasi modul AsposePdf. Terima objek jika berhasil.
  4. Panggil fungsi AsposePdfRotateAllPages.
  5. Putar semua file PDF. Rotasi diatur ke 270 derajat (on270). Jadi, jika ‘json.errorCode’ adalah 0, hasil operasi disimpan dalam “ResultRotation.pdf”. Jika parameter json.errorCode bukan 0 dan, akibatnya, muncul error di file Anda, informasi error akan berada dalam ‘json.errorText’.

  import AsposePdf from 'asposepdfnodejs';
  const AsposePdfModule = await AsposePdf();
  const pdf_file = 'Aspose.pdf';
  /*Rotate PDF-pages and save the "ResultRotation.pdf"*/
  const json = AsposePdfModule.AsposePdfRotateAllPages(pdf_file, AsposePdfModule.Rotation.on270, "ResultRotation.pdf");
  console.log("AsposePdfRotateAllPages => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);