Mbandhingake Word file utawa PDF nggunakake JavaScript SDK

Pustaka JavaScript sing kuat kanggo mbandhingake file ing PDF, Word, HTML, TXT, MD lan format liyane

Gunakake pamriksa prabédan JavaScript file, mbandhingake rong dokumen lan deleng prabédan ing antarane dokumen kasebut kanthi jelas ing output. Sampeyan ora perlu maneh mbandhingake dokumen kanthi manual. Elinga uga yen asil perbandingan bisa diekspor menyang DOCX, PDF, DOC lan liya-liyane.

Ndeleng potongan kode

Mbandhingake rong file ing JavaScript

Solusi Node kita dirancang kanggo menehi asil sing paling apik nalika nggunakake algoritma perbandingan sing rumit. Dadi, sampeyan ora perlu maneh kanthi manual nggoleki beda ing dokumen - bebas nggunakake API kita kanggo mbedakake rong file.

Mesin perbandingan kita nggoleki bedane ing tingkat karakter utawa kabeh tembung. Lan yen mung siji karakter diganti, kabeh tembung bakal disorot minangka diganti. Kabeh owah-owahan sing ditemokake bisa dideleng kanthi jelas ing output lan diekspor ing format sing trep.

Jinis perbandingan sing paling populer yaiku mbandhingake PDF file lan Word. Mula, kita bakal sinau alat diff Node lan fungsi perbandingan nggunakake conto kasebut.

Bandhingake PDF ing JavaScript

Kadhangkala sampeyan kudu nggawe manawa PDF dokumen sampeyan durung diowahi lan mbandhingake karo versi asli. Utawa sampeyan wis ngerti yen PDF sampeyan pancene wis diganti, lan sampeyan kudu nggoleki ngendi lan carane. Banjur sampeyan bisa mbandhingake rong versi PDF file lan ndeleng bedane. Lan supaya ora nindakake kanthi manual, gunakake Node diff checker API.

Kanthi solusi Node, sampeyan bakal bisa ndeleng owah-owahan cilik sing bisa gampang kantun ing perbandingan manual.

Bandhingake rong Word dokumen nggunakake JavaScript

Dokumen Word cukup gampang diganti, mula penting kanggo mbandhingake Word file kanggo mesthekake bagean utawa kabeh dokumen ora diganti.

Kanggo mbandhingake Word file, gunakake solusi Node, kaya PDF. Sampeyan bisa nindakake iki ing conto ing ngisor iki.

Bandhingake rong dokumen

Kanggo ndeleng kepiye cara mbandhingake dokumen Node, muat rong file sing pengin dibandhingake lan pilih format file ekspor.

Sawise mbandhingake rampung, dokumen kanthi diff bakal diundhuh kanthi otomatis ing format sing sampeyan pilih.

Penting yen dokumen sing dibandhingake kudu ora ana revisi sadurunge mbandhingake, mula kita kudu nampa kabeh revisi sadurunge mbandhingake diwiwiti. Aja kuwatir, kita wis ngurus ing conto kita:

Unggah file sing dibandhingake
Kode roto
Unggah file kapindho kanggo mbandhingake
Pilih format target saka dhaptar
import * as fs from "fs";

const wordsApi = new WordsApi("####-####-####-####-####", "##################");
const fileName1 = "Input1.docx";
const fileName2 = "Input2.docx";
const fileResult = "Output.docx";

//  Upload dokumen menyang panyimpenan maya.
const firstDocumentContent = fs.createReadStream(fileName1);
const uploadFirstFileRequest = new model.UploadFileRequest({
    fileContent: firstDocumentContent,
    path: fileName1
});

wordsApi.uploadFile(uploadFirstFileRequest)
.then((uploadFirstFileRequestResult) => {
    // tslint:disable-next-line:no-console
    console.log("Result of UploadFirstFileRequest: ", uploadFirstFileRequestResult);
    const secondDocumentContent = fs.createReadStream(fileName2);
    const uploadSecondFileRequest = new model.UploadFileRequest({
        fileContent: secondDocumentContent,
        path: fileName2
    });
    wordsApi.uploadFile(uploadSecondFileRequest)
    .then((uploadSecondFileRequestResult) => {
        // tslint:disable-next-line:no-console
        console.log("Result of UploadSecondFileRequest: ", uploadSecondFileRequestResult);

//  Mbandhingake dokumen ing awan.
        const compareDataOptions = new model.CompareData({
            author: "author",
            fileReference: model.FileReference.fromRemoteFilePath(fileName2)
        })
        const compareDocumentRequest = new model.CompareDocumentRequest({
            name: fileName1,
            compareData: compareDataOptions,
            destFileName: fileResult
        });
        wordsApi.compareDocument(compareDocumentRequest)
        .then((compareDocumentRequestResult) => {
            // tslint:disable-next-line:no-console
            console.log("Result of CompareDocumentRequest: ", compareDocumentRequestResult);

//  Download dokumen asil saka panyimpenan maya.
            const downloadFileRequest = new model.DownloadFileRequest({
                path: fileResult
            });
            wordsApi.downloadFile(downloadFileRequest)
            .then((downloadFileRequestResult) => {
                // tslint:disable-next-line:no-console
                console.log("Result of DownloadFileRequest: ", downloadFileRequestResult);
                fs.writeFileSync(fileResult, downloadFileRequestResult.body);
            });
        });
    });
});
Kode roto
  
Nyalin kode JavaScript menyang clipboard

Cara Mbandhingake rong versi file

  1. Pasang Aspose.Words Cloud for Node
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek JavaScript sampeyan
  3. Muat rong dokumen kanggo mbandhingake
  4. Nelpon metode compareDocument() kanggo mbandhingake rong dokumen
  5. Download dokumen asil saka panyimpenan maya

JavaScript perpustakaan kanggo nggunakake mbandhingake

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 paling populer kanggo mbandhingake operasi

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.