Atur warna latar belakang untuk PDF di Node.js
Contents
[
Hide
]
Jika Anda ingin mengatur warna latar belakang PDF, Anda dapat menggunakan AsposePdfSetBackgroundColor fungsi.
Silakan periksa cuplikan kode berikut untuk mengatur warna latar belakang PDF di lingkungan Node.js.
CommonJS:
- Panggil
requiredan imporasposepdfnodejsmodul sebagaiAsposePdfvariabel. - Tentukan nama file PDF yang ingin Anda atur warna latar belakangnya.
- Panggil
AsposePdfsebagai Promise dan lakukan operasi untuk mengatur warna latar belakang. Terima objek jika berhasil. - Panggil fungsi AsposePdfSetBackgroundColor.
- Setel warna latar belakang untuk file PDF. Anda harus mengirimkan 3 argumen ke fungsi ini: nama file input, warna yang diinginkan dalam format heksadesimal, dan nama file output. Jadi, jika ‘json.errorCode’ adalah 0, hasil operasi disimpan dalam “ResultRotation.pdf”. Jika parameter json.errorCode bukan 0 dan, akibatnya, muncul kesalahan dalam file Anda, informasi kesalahan akan berada di ‘json.errorText’.
const AsposePdf = require('asposepdfnodejs');
const pdf_file = 'Aspose.pdf';
AsposePdf().then(AsposePdfModule => {
/*Set the background color for the PDF-file and save the "ResultPdfSetBackgroundColor.pdf"*/
const json = AsposePdfModule.AsposePdfSetBackgroundColor(pdf_file, "#426bf4", "ResultPdfSetBackgroundColor.pdf");
console.log("AsposePdfSetBackgroundColor => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
});
ECMAScript/ES6:
- Impor
asposepdfnodejsmodul. - Tentukan nama file PDF yang ingin Anda atur warna latar belakangnya.
- Inisialisasi modul AsposePdf. Dapatkan objek jika berhasil.
- Panggil fungsi AsposePdfSetBackgroundColor.
- Atur warna latar belakang untuk file PDF. Warna latar belakang diatur menjadi “#426bf4,” yang merupakan kode warna heksadesimal yang merepresentasikan warna biru. Oleh karena itu, jika
json.errorCodebernilai 0, hasil operasi disimpan dalam “ResultRotation.pdf”. Jika parameterjson.errorCodetidak 0 dan, sesuai, muncul kesalahan dalam file Anda, informasi kesalahan akan terdapat dalamjson.errorText.
import AsposePdf from 'asposepdfnodejs';
const AsposePdfModule = await AsposePdf();
const pdf_file = 'Aspose.pdf';
/*Set the background color for the PDF-file and save the "ResultPdfSetBackgroundColor.pdf"*/
const json = AsposePdfModule.AsposePdfSetBackgroundColor(pdf_file, "#426bf4", "ResultPdfSetBackgroundColor.pdf");
console.log("AsposePdfSetBackgroundColor => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);