Merge PDF via JavaScript via C++

Merge PDF documents. Use Aspose.PDF for JavaScript via C++ to modify PDF files programmatically

Merge PDF files Using JavaScript via C++

When sending documents by email, merging PDF files can be useful in reducing the number of attached files. Instead of joining several separate PDF files, you can merge them into one file, making it more convenient for the recipient. If you need to print multiple PDF documents, merging them in advance can save time and effort. Instead of printing each file separately, you can combine them into one PDF. In order to merge PDF, we’ll use Aspose.PDF for JavaScript via C++ is a easy and secure toolkit used to work with PDF directly in the web browser. To install and use Aspose.PDF for JavaScript via C++ extract files from the ZIP archive.

How to Merge PDF files via JavaScript via C++


You need Aspose.PDF for JavaScript via C++ to try the code in your environment.

  1. Open first document.
  2. Open second document.
  3. Add pages of second document to the first.
  4. Save concatenated output file

JavaScript via C++ - example code to merge PDF file

Input file:

File not added

File not added

Output format:

Output file:


    var ffileMerge = function (e) {
        const file_reader = new FileReader();
        function readFile(index) {
        /*only two files*/
        if (index >= e.target.files.length || index >= 2) {
            /*merge two PDF-files and save the "ResultMerge.pdf"*/
            const json = AsposePdfMerge2Files(undefined, undefined, e.target.files[0].name, e.target.files[1].name, "ResultMerge.pdf");
            if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
            else document.getElementById('output').textContent = json.errorText;
            /*make a link to download the result file*/
            DownloadFile(json.fileNameResult, "application/pdf");
            return;
        }
        const file = e.target.files[index];
        file_reader.onload = function (event) {
            /*prepare(save) file from BLOB*/
            AsposePdfPrepare(event.target.result, file.name);
            readFile(index + 1)
        }
        file_reader.readAsArrayBuffer(file);
        }
        readFile(0);
    }