Tambah tandha banyu menyang PDF file utawa Word utawa mbusak tandha banyu sing wis ditambahake sadurunge nggunakake JavaScript

Kanthi perpustakaan Node iki, pangembang bisa nambahake gambar utawa watermark teks ing PDF dokumen utawa Word, uga mbusak tandha banyu sing wis ditambahake sajrone sawetara detik.

Nglindhungi dokumen saka distribusi ora sah lan nambah watermark online. Kanggo nindakake iki, mung mbukak PDF, Word utawa format dokumen liyane lan tambahake teks utawa watermark gambar nggunakake JavaScript. Banjur simpen PDF dokumen utawa Word sing ditandhani banyu ing format sing trep kayata DOC, DOCX, PDF, HTML, RTF, XPS lan liya-liyane. Sampeyan uga bisa mbusak tandha banyu saka dokumen supaya luwih gampang diproses kajaba nglanggar hak sapa wae.

Ndeleng potongan kode

Tambah watermark ing JavaScript

Kanthi API Node iki, pangembang bisa nambah tandha banyu menyang PDF, Word, utawa dokumen liyane kanthi online. Sampeyan bisa nggawe tandha banyu nggunakake teks utawa gambar banjur lebokake tandha banyu kasebut menyang PDF dokumen utawa Word kanthi nyetel sudut overlay ing JavaScript.

Cathetan: ora perlu nginstal aplikasi utawa perpustakaan pihak katelu. Mulane, solusi piranti lunak Node kita gampang banget digunakake.

Mbusak tandha banyu ing JavaScript

SDK Node sing diwenehake uga mbantu mbusak tandha banyu. Contone, mbusak watermark ing Word tegese sampeyan bisa mbukak Word dokumen sing dipengini kanthi prangko teks utawa watermark gambar, mbusak tandha banyu iki saka dokumen nggunakake JavaScript, banjur nyimpen file output ing format sing trep.

Watermark ing Word utawa PDF

Kanggo ngevaluasi API Node kita, muat dokumen sing pengin ditambahake watermark lan watermark minangka gambar utawa teks. Banjur pilih format file ekspor sing trep - DOCX, PDF, MD, HTML, TXT, DOC, RTF, EPUB, XPS lan liya-liyane.

Gunakake conto ing ngisor iki kanggo ndeleng cara kerjane:

File kudu nambah watermarks
Kode roto
Unggah gambar sing pengin dilebokake
Pilih format target saka dhaptar
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input1.docx");
const requestImageStream = fs.createReadStream("Input2.jpg");
const requestWatermarkData = new model.WatermarkDataImage({
    image: model.FileReference.fromLocalFileContent(requestImageStream)
});
const insertWatermarkRequest = new model.InsertWatermarkOnlineRequest({
    document: requestDocument,
    watermarkData: requestWatermarkData
});

wordsApi.InsertWatermarkOnline(insertWatermarkRequest)
.then((insertWatermarkResult) => {
    console.log("Result of InsertWatermarkImageOnline: ", insertWatermarkResult);

    const convertRequest = new model.ConvertDocumentRequest({
        document: insertWatermarkResult.Document.Values(),
        format: "docx"
    });

    wordsApi.convertDocument(convertRequest)
    .then((convertResult) => {
        console.log("Result of ConvertDocument: ", convertResult);
    });
});
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input.docx");
const requestWatermarkData = new model.WatermarkDataText({
    text: "This is the watermark text",
    layout: model.WatermarkDataText.LayoutEnum.Diagonal
})
const insertWatermarkRequest = new model.InsertWatermarkOnlineRequest({
    document: requestDocument,
    watermarkData: requestWatermarkData
});

wordsApi.insertWatermarkOnline(insertWatermarkRequest)
.then((insertWatermarkResult) => {
    console.log("Result of InsertWatermarkTextOnline: ", insertWatermarkResult);

    const convertRequest = new model.ConvertDocumentRequest({
        document: insertWatermarkResult.Document.Values(),
        format: "docx"
    });

    wordsApi.convertDocument(convertRequest)
    .then((convertResult) => {
        console.log("Result of ConvertDocument: ", convertResult);
    });
});
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");

const requestDocument = fs.createReadStream("Input.docx");
const deleteWatermarkOnline = new model.DeleteWatermarkOnlineRequest({
    document: requestDocument
});

wordsApi.deleteWatermarkOnline(deleteWatermarkOnline)
.then((deleteWatermarkOnlineResult) => {
    console.log("Result of DeleteWatermarkOnline: ", deleteWatermarkOnlineResult);

    const requestDocument = deleteWatermarkOnlineResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "docx"
    });

    wordsApi.convertDocument(convertDocument)
    .then((convertDocumentResult) => {
        console.log("Result of ConvertDocument: ", convertDocumentResult);
    });
});
Kode roto
  
Nyalin kode JavaScript menyang clipboard

Carane mbusak watermark ing JavaScript

  1. Pasang Aspose.Words Cloud for Node
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek JavaScript sampeyan
  3. Konfigurasi API nggunakake tombol app
  4. Muat dokumen sing pengin dibusak saka watermark
  5. Nggawe panjalukan kanggo mbusak watermark
  6. Simpen asil menyang format file sing trep

JavaScript perpustakaan kanggo nggunakake watermarks

Instal 'Aspose.Words Cloud SDK for Node.js' nggunakake manajer paket NPM. npm install asposewordscloud --save saka baris perintah kanggo nginstal SDK liwat manajer paket NPM. Minangka alternatif, sampeyan bisa kanthi manual kloning Aspose.Words Cloud SDK for Node.js saka GitHub lan nggunakake ing project. Tututi Instructions iki supaya cepet entuk kredensial keamanan sing dibutuhake lan ngakses REST API kita.

Requirements Sistem

  • @types/request (version 2.48.3+)
  • lodash (version 4.17.15+)
  • lodash.template (version 4.5.0+)
  • request (version 2.88.0+)
  • request-debug (version 0.2.0+)

Deleng Repository Documentation kanggo ndeleng rincian liyane.

Format dokumen paling populer kanggo nambah watermark

5%

Langganan kanggo Aspose Update Product

Entuk buletin saben wulan lan tawaran langsung dikirim menyang kothak layang.

© Aspose Pty Ltd 2001-2024. Kabeh hak dilindhungi undhang-undhang.