Sunting HTML ing Node SDK

Gunakake REST API kanggo nyunting HTML ing JavaScript kanthi terprogram

Nalika pangembang ngowahi HTML dokumen nganggo perpustakaan JavaScript iki, sing lagi diowahi yaiku Model Obyek Dokumen (DOM). Dadi, meh kabeh owah-owahan bisa ditindakake kanggo HTML dokumen sing diwakili minangka DOM. Kanthi Node SDK sing disedhiyakake, pangembang bisa kanthi gampang nyunting dokumen: ngowahi teks, nganyari tabel, nambah gambar lan liya-liyane. Cukup mbukak HTML, gawe owah-owahan sing dibutuhake kanthi program lan ekspor asil menyang format nyimpen sing padha utawa sing didhukung.

Ndeleng potongan kode

Sunting HTML ing JavaScript nggunakake REST API

Pustaka Node kita menehi pangembang kemampuan kanggo ngowahi HTML dokumen kanthi langsung kanthi nyunting Document Object Model (DOM), tegese ora ana piranti lunak tambahan sing kudu diinstal.

Sunting teks ing HTML file nggunakake JavaScript

Kasus sing paling populer kanggo nyunting HTML file yaiku nyunting teks. Kanthi solusi piranti lunak sing diwenehake, sampeyan bisa nambah, ngowahi utawa mbusak teks nggunakake JavaScript ing dokumen kasebut.

Sunting tabel ing HTML file nggunakake JavaScript

Pilihan editing HTML liyane sing populer yaiku nyunting tabel. Node SDK kita ngidini sampeyan nggarap tabel lan teks ing sel tabel.

Pangembang JavaScript bisa nambah utawa mbusak sel tabel lan tabel, uga nambah, ngowahi lan mbusak teks ing njero.

Tambah gambar menyang HTML file nggunakake JavaScript

Saliyane nyunting teks lan tabel ing HTML, ana pilihan umum liyane: nambahake gambar menyang dokumen ing JavaScript. Pangembang Node uga bisa nambah gambar menyang HTML file nggunakake DOM.

Sunting HTML kanthi terprogram

Coba Node SDK sing kuat iki lan evaluasi sawetara opsi ing panyuntingan HTML dokumen. Nggunakake conto ing ngisor iki, muat HTML dokumen lan gawe sawetara owah-owahan: nambah teks, nambah tabel lan sel tabel kanthi teks utawa lebokake gambar menyang HTML dokumen:

Unggah dokumen sing pengin diowahi
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("Input.html");
const requestParagraph = new model.ParagraphInsert({
    text: "Morbi enim nunc faucibus a."
})
const insertParagraphRequest = new model.InsertParagraphOnlineRequest({
    document: requestDocument,
    paragraph: requestParagraph
});

wordsApi.insertParagraphOnline(insertParagraphRequest)
.then((insertParagraphResult) => {    
    const requestDocument = insertParagraphResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "html"
    });

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

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

const requestDocument = fs.createReadStream("Input.html");
const requestTable = new model.TableInsert({
    columnsCount: 1,
    rowsCount: 2
})
const insertTableRequest = new model.InsertTableOnlineRequest({
    document: requestDocument,
    table: requestTable,
    nodePath: ""
});

wordsApi.insertTableOnline(insertTableRequest)
.then((insertTableResult) => {    
    const requestDocument = insertTableResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "html"
    });

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

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

const requestDocument = fs.createReadStream("Input1.html");
const requestDrawingObject = new model.DrawingObjectInsert({
    height: 0,
    left: 0,
    top: 0,
    width: 0,
    relativeHorizontalPosition: model.DrawingObjectInsert.RelativeHorizontalPositionEnum.Margin,
    relativeVerticalPosition: model.DrawingObjectInsert.RelativeVerticalPositionEnum.Margin,
    wrapType: model.DrawingObjectInsert.WrapTypeEnum.Inline
})
const requestImageFile = fs.createReadStream("Input2.html");
const insertDrawingObjectRequest = new model.InsertDrawingObjectOnlineRequest({
    document: requestDocument,
    drawingObject: requestDrawingObject,
    imageFile: requestImageFile,
    nodePath: "sections/0"
});

wordsApi.insertDrawingObjectOnline(insertDrawingObjectRequest)
.then((insertDrawingObjectResult) => {    
    const requestDocument = insertDrawingObjectResult.Document.Values();
    const convertDocument = new model.ConvertDocumentRequest({
        document: requestDocument,
        format: "html"
    });

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

Cara Ngowahi HTML ing JavaScript

  1. Pasang 'Aspose.Words Cloud kanggo Node'
  2. Tambah referensi perpustakaan (ngimpor perpustakaan) menyang proyek JavaScript sampeyan
  3. Muat HTML kanggo nyunting ing JavaScript
  4. Lebokake isi ing wiwitan HTML
  5. Download dokumen asil saka panyimpenan maya

Pustaka JavaScript kanggo nggunakake panyuntingan HTML.

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 file liyane sing didhukung

Sampeyan bisa nindakake operasi suntingan kanggo format file liyane:

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.