Bookmarks in PDF in Node.js

Delete a Particular Bookmark from a PDF Document

You can delete bookmarks from a PDF file using Aspose.PDF for Node.js via C++. In case you want to delete bookmarks from a PDF, you can use AsposePdfDeleteBookmarks function. Please check the following code snippet in order to delete bookmarks from a PDF file in Node.js environment.

CommonJS:

  1. Call require and import asposepdfnodejs module as AsposePdf variable.
  2. Specify the name of the PDF file from which the bookmarks will be removed.
  3. Call AsposePdf as Promise and perform the operation for removing bookmark. Receive the object if successful.
  4. Call the function AsposePdfDeleteBookmarks.
  5. Delete bookmarks. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteBookmarks.pdf”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

    const AsposePdf = require('asposepdfnodejs');
    const pdf_file = 'Aspose.pdf';
    AsposePdf().then(AsposePdfModule => {
        /*Delete bookmarks from a PDF-file and save the "ResultPdfDeleteBookmarks.pdf"*/
        const json = AsposePdfModule.AsposePdfDeleteBookmarks(pdf_file, "ResultPdfDeleteBookmarks.pdf");
        console.log("AsposePdfDeleteBookmarks => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
    });

ECMAScript/ES6:

  1. Import the asposepdfnodejs module.
  2. Specify the name of the PDF file from which the bookmarks will be removed.
  3. Initialize the AsposePdf module. Receive the object if successful.
  4. Call the function AsposePdfDeleteBookmarks.
  5. Delete bookmarks. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteBookmarks.pdf”. If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.

    import AsposePdf from 'asposepdfnodejs';
    const AsposePdfModule = await AsposePdf();
    const pdf_file = 'Aspose.pdf';
    /*Delete bookmarks from a PDF-file and save the "ResultPdfDeleteBookmarks.pdf"*/
    const json = AsposePdfModule.AsposePdfDeleteBookmarks(pdf_file, "ResultPdfDeleteBookmarks.pdf");
    console.log("AsposePdfDeleteBookmarks => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);